Skip to content

Environment-Specific Migrations Made Easy (for test data) #536

Closed
@inadarei

Description

@inadarei

I'm submitting a...


[ ] Bug report  
[x] Feature request

Current behavior

If you wanted to write a migration that only runs in certain environment(s), currently you would have to implement it in Javascript by analyzing db.internals.argv.env in exports.up. If many of your migrations are environment-specific this can get tedious and error-prone.

An important use-case where you may want to run some migrations in certain environments and not in others is the case of test data. It is extremely useful if your migrations can set up appropriate test data for:

  1. integration tests
  2. user-acceptance tests in QA environment
  3. development environments so that devs don't code against empty data.
    etc.

Expected behavior

Configuring environmental context of a migration should require no coding and be descriptive, via configuration.

For instance, in configuration you should be able to indicate something along the lines of:

{
  "dev": {
    "driver": "sqlite3",
    "filename": "~/dev.db"
  },

  "test": {
    "driver": "sqlite3",
    "filename": ":memory:"
  },

  "prod": {
    "driver": "mysql",
    "user": "root",
    "password": "root",
    "skip_migrations" : [
     "20171128161750-insert-dummy-users.js",
     "20171221211431-insert-dummy-products.js", 
    ]
  },

}

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Supporting test data for applications in an easy and elegant way, via migrations.

Environment


db-migrate version: X.Y.Z
plugins with versions: X.Y.Z
db-migrate driver with versions: 

Additional information:
- Node version: XX  
- Platform:  

Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions