Taking the headache out of db migrations
- postgres
- mysql
- ... @todo more
yarn add -D @teleology/migraine
Make sure the environment variable DATABASE_URL is exported in whatever cli you are currently using.
export DATABASE_URL='postgres://postgres:admin@localhost:5432/database?schema=public'
To view which migrations you already have run:
migraine show
Create a <filename>.up.sql
and <filename>.down.sql
:
migraine create <some random name>
*Note: all whitespace and uppercase characters will be converted to a lower snakecase.
Run ALL migration files not previously ran:
migraine up
Run a specific number of up migrations:
migraine up -c <number>
Run a specific migration file:
migraine up -m <filename>
*Note: Do not include the .up.sql
portion of the file name
Revert ALL migration files and drop migraine table:
migraine down
Revert a specific number of migrations:
migraine down -c <number>
Revert a specific migration file:
migraine down -m <filename>
*Note: Do not include the .down.sql
portion of the file name