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

How does this tool work with existing schemas? #96

Closed
thomasdziedzic-pd opened this issue Oct 1, 2019 · 1 comment
Closed

How does this tool work with existing schemas? #96

thomasdziedzic-pd opened this issue Oct 1, 2019 · 1 comment

Comments

@thomasdziedzic-pd
Copy link
Contributor

I have a large existing schema that was manually created.

What are the steps to getting dbmate up to date with this schema and start tracking database migrations through dbmate?

Is there any kind of automation that you can suggest?

@amacneil
Copy link
Owner

amacneil commented Oct 1, 2019

This should be fairly straight forward. Ideally, you will have a set of migrations which can recreate the current state of your database from scratch (for development etc). In your case, you just want to have a first migration which will create any existing state you have in production.

You can use the dbmate dump command to generate db/schema.sql file containing your current database schema. Then, run a dbmate new import_existing or similar to create a new migration file (under db/migrations/), and copy the relevant table definitions into this file. You can then (in development only - NOT production!) run dbmate drop && dbmate up to try recreating a new development/test database from your migration files.

@amacneil amacneil closed this as completed Jan 2, 2020
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

2 participants