Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple migration directory support #401

Open
joezappie opened this issue Oct 7, 2021 · 3 comments
Open

Multiple migration directory support #401

joezappie opened this issue Oct 7, 2021 · 3 comments

Comments

@joezappie
Copy link

joezappie commented Oct 7, 2021

Is your feature request related to a problem? Please describe.

I'm switching from postgres + knex to mongodb and a feature knex has is the ability to specify multiple migration directories. All it does is combine all the migrations and sorts thems in the correct order.

My reason for needing something like this is I have generic migrations and then migrations specific to clients. I need to be able to run all the generic migrations along with any client migrations.

For example consider the following migrations:

  • migrations/generic/1633521000_users.js
  • migrations/generic/1633572000_sales.js
  • migrations/client_1/1633553000_users.js
  • migrations/client_2/1633587000_sales.js

In this example, I want to run the migration for client_1. I would provide both the migration folders migrations/generic and migrations/client_1. This would run the following migrations in this order:

  1. migrations/generic/1633521000_users.js
  2. migrations/client_1/1633553000_users.js
  3. migrations/generic/1633572000_sales.js

client_2 migrations would not be run in this case.

Describe the solution you'd like

The way knex handles this is in the config, their migration directory can either be a string or array of strings. I think this is the cleanest way

directory: a relative path to the directory containing the migration files. Can be an array of paths (default ./migrations)

Describe alternatives you've considered

By only having the ability to specify one migration directory, I would have to copy and paste the generic migrations into each clients folder which I do not want to do.

I don't think its possible to run the generic migrations and client migrations separate. If a generic migration had a date later than the client migration it wouldn't run it.

This is my specific use case, but I think there's a lot of benefits to this, a big one being able to better organize your migrations.

I am open to donating for this feature if you have something setup for that. Let me know how much you would think is fair for this feature if you want.

@BifrostBuilder
Copy link

You could use the API that the package offers to feed it a different migrations directory and a different connection string. Or use the -f parameter to provide a different configuration file from the command line.

@stascnb
Copy link

stascnb commented Sep 12, 2022

yea, its a good thing,

I myself would like to seperate into a few folders,

  1. Seed data
  2. Migrations

Wish there was an easier way,

@erlindcekaj I couldnt see anything for -f would u mind sharing how uve done it?

@dpanda-hv
Copy link

Any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants