Document integration of dbmate on a existing schema #362
Replies: 2 comments
-
There are two ways to integrate dbmate into an existing schema: 1) Do nothing, start using dbmate going forward You can simply start using dbmate, and add/edit your existing schema. Dbmate is intentionally rather dumb, so we will attempt to apply each migration and it is up to you to ensure that the migration is valid based on the existing schema of the database. This is the simplest approach, but the downside is that you will not be able to recreate a development or testing database with a full schema by simply using the 2) Import your current schema into dbmate The other option is to create an initial migration which can recreate your current schema. The advantage of this is that you can recreate your entire schema in development or test whenever needed. There are three steps to this: First, export your current schema. You can export the current schema using Next, copy this schema into a new migration. For example, run Finally, you will need to manually insert the migration number into your production database so that dbmate doesn't try to apply this migration in production (i.e. you need to tell dbmate that this migration was already applied). To do this you will need to make sure your Now, your production database will know that the Does that answer your question? |
Beta Was this translation helpful? Give feedback.
-
That is basically how I finally did it. It would be nice to have that in the README.md, and perhaps a command to do 2. |
Beta Was this translation helpful? Give feedback.
-
Description
The documentation should describe the process to integrate
dbmate
into an existing schema.After a first look at the docs it looks like the process should be something like this:
But this will only work on an existing database if we want to create a new database from scratch we need to apply the initial dump first. Is there any better way to do this?
Beta Was this translation helpful? Give feedback.
All reactions