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

Configurable migration table name #4

Closed
ThomWright opened this issue Dec 9, 2017 · 7 comments
Closed

Configurable migration table name #4

ThomWright opened this issue Dec 9, 2017 · 7 comments

Comments

@ThomWright
Copy link
Owner

The fixed migration table name is a bit meh, would be useful to configure it.

Would it be useful to be able to specify a schema for the migration table?

@rafakato

@rafakato
Copy link
Contributor

It's something that takes no time to implement, but will need to implement a custom insert function or only allow to add more fields to the current schema, and for me personally I don't think it's necessary.

@ThomWright

@rafakato
Copy link
Contributor

Within the changes to implement custom migration table name, I'll also do:

  • support to schema name
  • support to connection uri;
  • normalize modules exports (I was reading this article and even that import/export is not used we still get the refactoring benefit);

@boblauer
Copy link
Contributor

I have the need for a configurable migration table, as I want to run migrations from several different applications against the same database, and so I'll have multiple files with the same index (e.g. app1/migrations/1-app1-stuff.sql and app2/migrations/1-app2-stuff).

I'm happy to open a pull req, but am having trouble understanding this sentence from above:

but will need to implement a custom insert function or only allow to add more fields to the current schema

My thinking is that this task would require two updates:

  1. Update the hard-coded migration table name variable at https://github.com/ThomWright/postgres-migrations/blob/master/src/migrate.js#L33 to read in a config value, and default to "migrations".

  2. Update https://github.com/ThomWright/postgres-migrations/blob/master/src/migrations/0_create-migrations-table.sql to include the dynamic table name.

Does this approach sound correct?

@rafakato
Copy link
Contributor

Hi @boblauer, I've read your PR and did one implementation using js file to try to avoid the problem you cite with hash. #13

@ThomWright
Copy link
Owner Author

@boblauer Before I have a look at the PR I'd like to get a better understanding of your use case, to make sure this is the best solution to the problem.

Specifically I'm interested in:

I want to run migrations from several different applications against the same database

Something doesn't feel right about this to me. Could you explain a bit more about why things are set up this way, rather than each application having its own database?

The problem I see is that each application could be trying to migrate the same database in different directions, and they could all have inconsistent views on what the current state is.

@boblauer
Copy link
Contributor

boblauer commented Jun 7, 2018

Sure thing. These smaller applications make up a larger ecosystem, for lack of a better word. So they all share a few common tables, such as user, but they also have their own tables specific to their functionality.

Each app will only modify the tables that it is responsible for. In other words, if the app wasn't responsible for creating the table, it will never make updates to the table.

@ThomWright
Copy link
Owner Author

This sounds like a microservice architecture where the services are using the database as their integration point.

This is generally considered an anti-pattern, and not something I want to support.

Here are some resources to learn more about this:

If you are working on a microservices-style system, I'd also recommend Building Microservices by Sam Newman.

Admittedly I don't know anything about your application or use-case, but I would advise keeping the services separate, with their own databases. If several of them need access to e.g. user data, they should communicate with each other or duplicate the data.

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

3 participants