Skip to content

Commit

Permalink
Merge branch 'feature/initial-setup' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Adibla committed Nov 16, 2022
2 parents e7c3224 + 4abf93f commit 72a1790
Show file tree
Hide file tree
Showing 46 changed files with 944 additions and 759 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
dist
node_modules
.idea
coverage
.husky
package
bin/**/*.js
92 changes: 92 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

1. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
2. Update the README.md with details of changes to the interface, this includes new environment
variables, exposed ports, useful file locations and container parameters.
3. Increase the version numbers in any examples files and the README.md to the new version that this
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
do not have permission to do that, you may request the second reviewer to merge it for you.

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
148 changes: 107 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
[![LinkedIn][linkedin-shield]](https://www.linkedin.com/in/andrea-di-blasi-888850b2/)



<!-- PROJECT LOGO -->
<br />
<div align="center">
<h1 align="center">Ares</h1>
<h3 align="center">Andrew Release Execution Scripts</h3>
<h3 align="center">Andrea Release Execution Scripts</h3>
________________________($$$$$$$$$)__________________________
_________________________($$$$$$$)___________________________
_______________________($$$$$$$$$$$)_________________________
Expand Down Expand Up @@ -139,7 +138,7 @@ _____________________________($)_____________________________
<!-- ABOUT THE PROJECT -->
## About The Project

Ares is a tool that you can use to release migration scripts into your MongoDB or Mysql instance.
Ares allows you to release migration scripts to your MongoDB or Mysql instance.
<p align="right">(<a href="#readme-top">back to top</a>)</p>


Expand All @@ -148,9 +147,28 @@ Ares is a tool that you can use to release migration scripts into your MongoDB o

<p align="right">(<a href="#readme-top">back to top</a>)</p>

### Installation with npm

_Here is a step-by-step guide to installing this cli using NPM._

1. Use npm to install ares in your project folder
```sh
npm i ares
```
2. Change the [config files](#usage) or [env variables](#usage) to update your database connection info

3. Using Ares or manually, create one or more migrations and place them in the MIGRATIONS_DIR folder (default data-ares on your project root).
```sh
ares --operation create --name test --dbms MYSQL
```
4. Run with
```sh
ares --operation up
```

### Installation with local clone

_Below is showed how to install this cli with local clone._
_Here is a step-by-step guide to installing this cli using local clone._

1. Clone project using git
```sh
Expand All @@ -164,7 +182,7 @@ _Below is showed how to install this cli with local clone._
```sh
npm i
```
4. Update your db connection info using [env variables](#usage) env variables or changing [config files](#usage)
4. Change the [config files](#usage) or [env variables](#usage) to update your database connection info

5. Run with
```sh
Expand All @@ -178,7 +196,8 @@ _Below is showed how to install this cli with local clone._

<!-- USAGE EXAMPLES -->
##Usage
Set necessary ENV variables to specify your db config (or you could update config files located under /config)
Specify your database configuration via ENV variables (or use USE_CUSTOM_CONFIG=true and update PROJECT/config/{env}.json)

WINDOWS
```sh
set DB_HOST="localhost"
Expand All @@ -201,73 +220,120 @@ UNIX
export AUTH_SOURCE="test"
export SERVICE_NAME="test" //for logging
```
And then run the app, Ares creates a new table in your db with automatically generated migrations, the name of this collection is specified by MIGRATIONS_STORE env (migrations-store by default).
```sh
npm run start -- --operation up
```
All existing migrations up commands in/src/data will be executed and their status will be saved in db.
Currently the folder contains some examples of migrations.
This pattern must be followed if you use config files
```
{
"db": {
"connection": {
"host": "localhost",
"port": 27017,
"user": "admin",
"password": "secret",
"database": "test",
"authMechanism": "DEFAULT",
"authSource": "admin"
},
"migrationsStoreTable":{
"tableName": "migrations-store",
"tableId": "id"
},
"seeds": {
"directory": "./priv/seeds"
}
},
"app":{
"migrationsDir": "./ares-data",
"operationsLabels": {
"statusExecuted": "EXECUTED",
"statusRolledBack": "ROLLED_BACK",
"statusPending": "PENDING",
"rolledBackSuccess": "ROLLED_BACK_SUCCESS",
"rolledBackFailed": "ROLLED_BACK_FAILED",
"outcomeSuccess": "COMPLETE_SUCCESS",
"outcomeFailed": "COMPLETE_FAILED",
"outcomeMissing": "NONE"
}
},
"log": {
"name": "app",
"base": {
"env": "dev"
},
"enabled": true,
"level": 20
}
}
```

After running the app, Ares creates a new table in your database with generated migrations (included in your MIGRATIONS_DIR), whose name is specified by MIGRATIONS_STORE env (migrations-store by default).

<span style="color: red">IMPORTANT</span> CURRENTLY THE FIRST MIGRATION DICTATES WHICH DBMS WILL BE USED (for multiple dbms supports, see [Roadmap](#Roadmap)
```sh
ares --operation up
```
We will execute all migrations' up commands in the MIGRATIONS_DIR folder and save their status in the database.
There are currently some migration examples in the folder.

### ENVIRONMENT VARIABLES
There are several environment variables that you could use in order to config the application (someone has default value)
In order to configure the application, you can use several environment variables (someone has default values).
```sh
DB_HOST="localhost" #required
DB_PORT=27017 #required
DB_USER="test" #required
DB_PASS="test" #required
DB_USER="admin" #required
DB_PASS="secret" #required
DB_NAME="test" #required
AUTH_MECHANISM="test"
AUTH_SOURCE="test"
USE_CUSTOM_CONFIG=false #It is used to include custom config files (instead of using env) located in ProjectDir/config/[env].json.
AUTH_MECHANISM="DEFAULT"
AUTH_SOURCE="admin"
SERVICE_NAME="test"
SERVICE_NAME="test"
MIGRATIONS_STORE="test" #name of tbl support for migrations, used by Ares
MIGRATIONS_STORE_ID="test" #primary key of tbl support for migrations, used by Ares
MIGRATIONS_DIR="/src/data" #folder with migrations file (default=/src/data)
STATUS_EXECUTED="COMPLETE_SUCCESS" #status if migration goes up with success
STATUS_ROLLED_BACK="STATUS_ROLLED_BACK" #status if migration rolledback
STATUS_PENDING="STATUS_PENDING" #status migration pending
ROLLED_BACK_SUCCESS="ROLLED_BACK_SUCCESS" #status if migration rolledback with success
ROLLED_BACK_FAILED="ROLLED_BACK_FAILED" #status if migration rolledback with error
OUTCOME_SUCCESS="OUTCOME_SUCCESS" #status if migration up with error
OUTCOME_FAILED="OUTCOME_FAILED" #status if migration goes up with success
OUTCOME_MISSING="OUTCOME_MISSING" #status if migration up with no outcome
MIGRATIONS_STORE="migrations-store" #Migration support table used by Ares for migrations
MIGRATIONS_STORE_ID="test" #The primary key of the migration table used by Ares for migrations
MIGRATIONS_DIR="./ares-data" #Folder that includes migrations file
STATUS_EXECUTED="COMPLETE_SUCCESS" #Status of migration if it is successful
STATUS_ROLLED_BACK="STATUS_ROLLED_BACK" #Status of migration if it is rolledback
STATUS_PENDING="STATUS_PENDING" #Status of migration if it is pending
ROLLED_BACK_SUCCESS="ROLLED_BACK_SUCCESS" #Result of migration if it is rolled back with success
ROLLED_BACK_FAILED="ROLLED_BACK_FAILED" #Result of migration if it is rolled back with errors
OUTCOME_SUCCESS="OUTCOME_SUCCESS" #Result of migration if it is successful
OUTCOME_FAILED="OUTCOME_FAILED" #Result of migration if it is failed
OUTCOME_MISSING="OUTCOME_MISSING" #Status of migration if no outcome is achieved
```

### COMMAND LINE OPTIONS

It executes all migrations' up commands contained in MIGRATIONS_DIR
```sh
npm run start -- --operation up
ares --operation up
```
It executes all migrations' down commands contained in MIGRATIONS_DIR, **YOU CAN ONLY USE DOWN COMMAND FOR ALREADY DONE MIGRATIONS IN OUTCOME "COMPLETE_SUCCESS"**
```sh
npm run start -- --operation down
ares --operation down
```

It executes only migrations' with id specified (if exist) with up commands, contained in MIGRATIONS_DIR
```sh
npm run start -- --operation up --migration 001 002
ares --operation up --migration 001 002
```

It executes only migrations' with id specified (if exist) with down commands, contained in MIGRATIONS_DIR, **YOU CAN ONLY USE DOWN COMMAND FOR ALREADY DONE MIGRATIONS IN OUTCOME "COMPLETE_SUCCESS"**
```sh
npm run start -- --operation down --migration 001 002
ares --operation down --migration 001 002
```

It creates new migration schema in MIGRATION_DIR, you have to specify --name (migration's name) param and --dbms (mysql or mongodb) and you could optionally includes other not required params (author, description, tags)
```sh
npm run start -- --operation create --name test --author andrea --dbms mysql
npm run start -- --operation create --name test --author andrea --dbms mysql --description desc --tags tag1 tag2
ares --operation create --name test --author andrea --dbms MYSQL
ares --operation create --name test --author andrea --dbms MYSQL --description desc --tags tag1 tag2

```

### MIGRATION ENTITY SPECIFICATION
Filename of migration can contains title,id and author, delimitated by "-", for example: "001-example-andrea.json", but the same attributes could be included in json body. Currently json is the only filetype supported.
A migration filename may include title, id, and author, separated by "-", for example, "001-example-andrea.json", but the same attributes may also be included in the migration body. Currently, json is the only filetype supported.
Migration entity contains these attributes, they will be persisted in Ares' config table.

- **id** (string) - Migration's id, it could be specified in filename or body
- **author** (string) - Migration's author, it could be specified in body or filename.
- **dbms** (string 'mysql'|'mongodb') - Migration's dbms, it could be specified only in body.
- **author** (string) - Migration's Author, it could be specified in body or filename.
- **dbms** (string 'MYSQL'|'MONGODB') - Migration's dbms, it could be specified only in body.
- **tag**(string) - Migration's tag, it could be specified only in body.
- **description**(string) - Migration's description, it could be specified only in body.
- **comment**(string) - Migration's comment, it could be specified only in body.
Expand All @@ -283,7 +349,7 @@ Migration entity contains these attributes, they will be persisted in Ares' conf
- **created_at**(date) - Migration's creation timestamp (automatically generated)

### TEST
You can run unit test (using jest) with
Unit tests can be run using Jest
````sh
npm run test
````
Expand All @@ -302,8 +368,8 @@ npm run test
- [x] Add back to top links
- [ ] Custom messages for some use cases (already existing migration exc...)
- [ ] Improve errors management
- [ ] Manage multiple dbms in single transaction
- [ ] Reuse MongoDB connection, no multiple instances
- [ ] Manage multiple dbms in single transaction (think about that)
- [ ] Connect to MongoDB once, no need to create multiple instances
- [ ] Remove "any" everywhere and use types for everything
- [ ] Other dbms support
- [ ] Validation checksum
Expand Down
Loading

0 comments on commit 72a1790

Please sign in to comment.