Sign inSign up

clientcommand/migration

By clientcommand

•Updated 6 months ago

A migration tool for mysql and postgres databases.

Image
0

6.0K

clientcommand/migration repository overview

⁠Usage:

You'll need a folder with sql files in it. Here's an example of how your files should look:

db
- 2019_04_12_00_00_m.sql
- 2019_04_13_01_22_m.sql
- 2019_04_14_12_55_m.sql
...

⁠Instructions:

Pushing to the master repository will trigger a build on Docker Hub at clientcommand/migration. In your docker-compose.yml file, use the following:

....
migration:
    image: clientcommand/migration
    environment:
    - "Host=db"
    - "User=root"
    - "Password=password"
    - "Port=3306"
    - "Database=mydb"
    volumes:
    - ./db:/app/db
    depends_on:
    - db
    links:
    - db
....

⁠Seed Scripts

Seed scripts allow you to seed a database with example data.

Important: Seed scripts should be alphabetically organized directly below the migration in which it affects.

To use the "seed" script functionality, you'll need to set an environment variable and have the appropriate seed scripts located in your migration folder.

....
    environment:
    - "RunSeedScripts=true"

(Do not set this to true in a production environment)

The filename structure is as follows: *_s.sql

For example: 2019_04_10_00_00_s.sql

⁠Init Scripts

Init scripts allow you to rebuild a database completely from one single sql file. These are only useful for local test environments.

Important: Init scripts should be the first scripts alphabetically placed. Ideally, using a numerical system as the prefix to the filename. This would look like the following: 01_database_schema_i.sql

To use the "init" script functionality, you'll need to set an environment variable.

....
    environment:
    - "RunInitScripts=true"

(Do not set this to true in a production environment)

The filename structure is as follows: *_i.sql

For example: 2019_04_10_00_00_i.sql

⁠Custom Directory

To use a custom path (instead of ./db), set the following environment variable:

....
    environment:
    - "CustomDirectory=/my-dir/"

This directory can be either a relative or absolute path.

⁠Dry Run

Sometimes, you don't want to run the migrations without first seeing what will be ran. To use this, set the following environment variable:

....
    environment:
    - "DryRun=true"

⁠Summary

In conclusion, if you are using migrations, seed scripts, and init scripts; your directory should look like as follows:

db
- 2019_04_12_00_00_i.sql
- 2019_04_13_01_22_m.sql
- 2019_04_14_12_55_s.sql
...

Tag summary

Content type

Image

Digest

sha256:f93d41e85…

Size

78.9 MB

Last updated

6 months ago

docker pull clientcommand/migration