graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using graphile-migrate with an existing project

c42f opened this issue · comments

Hi, I'm working on a project which has an existing database, but no formal migration strategy.

How do I get up and running with graphile-migrate? I'm guessing that I could create a single big "migration" which contains the entire schema to start with, so that the shadow database can be populated.

But how do I make sure that this plays nicely with a production database which has had no migrations applied to it, to date? Clearly we don't want to apply this first huge "migration" to production, but only future migrations.

The trick for this is to have that initial schema be used in the afterReset hook. afterReset is only used when a DB is reset (i.e. when you have Graphile Migrate create it) and thus it won't be a concern for production since you never run reset there. Graphile Migrate's first migration will be the first changes you want to apply to production.

[semi-automated message] Thanks for your question; hopefully we're well on the way to helping you solve your issue. This doesn't currently seem to be a bug in the library so I'm going to close the issue, but please feel free to keep requesting help below and if it does turn out to be a bug we can definitely re-open it 👍

You can also ask for help in the #help-and-support channel in our Discord chat.

Perfect, thanks very much!

If I end up using this in production, I could add something about my "getting started from scratch" experience to the docs. Would you be interested, and where would you see it fitting in?

Yes please! Put it below drift but then link it from Getting Started and maybe another place or two if it makes sense to do so. Something like “If you already have a database schema, see [Using Migrate with an existing database] for some tips”