A collection of database models for use with [Sequelize ORM](https://sequelize.org/).
npm install @text2order/sequelize-modelsInstall dependencies:
npm i or npm install
To apply schema changes to a database:
npm run migrate:up
To verify that the database you are running against is compatible with your version of the schema:
npm run checkSchema
Using the models requires that the following environment variables are set:
- DATABASE_HOST
- DATABASE_DB_NAME
- DATABASE_USER
- DATABASE_PASSWORD
- DATABASE_LOGGING (set to "off" to turn logging off)
- MODEL_CHANGE_LOGGING (set to "off" to turn model change logging off)
- DB_POOL_MAX (database max connection pool. If not set, default to 5)
- DB_POOL_MIN (database min connection pool. If not set, default to 0)
- DB_POOL_ACQUIRE (database acquire. If not set, default to 30000)
#### Using dotenv
Copy the .env-template file to .env and set variables accordingly.
npm run migrate:check`$3
To create a migration run
`npm run migrate:create [migrationName]`This creates an up and down migration in the migrations/sqls directory and create the js file in migrations. To add your migrations to these files write plane sql in the corresponding up and down file to add and remove your change.
Once your migration is added you will also need to make the change to the model in src/models/[modelName]
$3
To run migartions run
`npm run migrate:up`$3
To undo the last migration `run npm run migrate:down`Testing
$3
#### Database Setup
The unit tests in this repository require a local MySQL instance and will modify the data in that database. A
.env file should be created including environment variables specific to the test environment as found in config/database.json in addition to the environment variables specified above.`
DATABASE_HOST_TEST=localhost
DATABASE_NAME_TEST=vector-test
DATABASE_USER_TEST=test
DATABASE_PASSWORD_TEST=test
`The variables
DATABASE_NAME_TEST, DATABASE_USER_TEST, and DATABASE_PASSWORD_TEST are used in setting up MySQL and can be set to almost any valid string. #### Run Tests
npm test`