0.0.37 • Published 1 year ago

@text2order/sequelize-models v0.0.37

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Sequelize Models

A collection of database models for use with Sequelize ORM.

Table of Contents

tldr;

Install 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

Getting Started

Configuration

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.

How to publish

This package is published but a github action. For this action to work bump the package version according to semver and push. (Right now this package is still considered in beta so do NOT publish a major version ex 1.0.0) as long as the package version is newer it will publish it to npm. Once it is published you can update the version numbers in the applications that use this package.

Migrations

Gotchas

If you are writing a migration that removes a column make sure that you do this in two steps. First release a change that removes the column from the model. Make sure that all applications using this package have that version. Affer all applications are on that version write the migration to remove it from the database. This is becasue a model in an application that is not updated might reference the column and if it is not on the database it will throw an error.

How to check if there are migrations to run

npm run migrate:check

How to create

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

How to run migrations

To run migartions run npm run migrate:up

How to undo a migration

To undo the last migration run npm run migrate:down

Testing

Running Tests

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

0.0.37

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.36

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.29

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.26

1 year ago

0.0.23

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.19

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago