mattes / migrate

Database migrations. CLI and Golang library.
Other
2.29k stars 326 forks source link

possible to create test DB based on existing DB schema? #313

Open armhold opened 6 years ago

armhold commented 6 years ago

Rails has a feature whereby the foo_test database is dropped and then re-created based on the current foo schema, prior to running tests. This allows for things like integration tests that hit the database, and helps keep test runs from interfering with each other by leaving behind crud. Rather than running individual migrations, I believe Rails just copies the schema from foo.

Is there a way to do this (or something close to it) with migrate? Not sure how feasible it is to implement this programmatically in a cross-db fashion, but it sure would be nice to have.

For the moment, I just use the following command line with postgres:

$ dropdb foo_test && createdb foo_test && pg_dump -s foo | psql foo_test

I'd love to know how other people are currently solving this problem. Thanks.