Open ryanberckmans opened 4 years ago
A way to implement this might be a wrapper that takes schema.sql
as input, creates an ephermal postgres instance via docker, applies schema.sql
to it, diffs that ephemeral instance against postgresql:///prod-db
, and then destroys the ephemeral instance.
Perhaps this wrapper shell script could be added to this repo for reference.
This is definitely the roadmap. In the short term, if you're comfortable with python you can script this up fairly straightforwardly yourself (there's some relevant code in the dev usage section of the docs). These temporary databases use a locally running postgres instance but it would be great to support docker too.
And I agree if this was out of the box it would be great as the use case you describe is very common. There's some complexity to work through with making sure the user has the right container image downloaded and available to use etc, but worth it for the convenience and easy cleanup that docker containers provide.
A good example of using static schema.sql
as a migra input is https://github.com/bikeshedder/tusker
I just released Tusker 0.2.0 with the help of @Swizz that supports diffing a schema
file, migration
files and an actual database
. It uses migra
for all diffing purposes but provides a different user interface.
Could migra support a *.sql file as the source schema?
My thought is that I'd like to maintain a
schema.sql
, which is the authoritative schema for my DB. Then, I'd like to runmigra postgresql:///prod-db schema.sql
to generate the statements which must be run for DBprod-db
to match schema.sql.
Hi @ryanberckmans. Glad to see we're touring around in the same repos. Great issue!
Instead of only 1 schema.sql file, could this also work with *.sql ? We have schema split into multiple sql files. When run in alphabetical order, dependencies are also met (eg 10-tables.sql, 12-more-tables.sql, 20-views.sql ...)
Social comment:
@tzaffi hey, Zeph! Great to see you out in the wild, haha. I hope things are well!
It looks like I missed the ping in December and saw it now, thanks to mariusa.
Tusker supports globbing patterns as schema input since version 0.3: https://github.com/bikeshedder/tusker/blob/master/CHANGELOG.md
It's a very thin wrapper over migra
and provides some convenience features.
Also mentioned here: https://github.com/djrobstep/migra/issues/25#issuecomment-449711551
Could migra support a *.sql file as the source schema?
My thought is that I'd like to maintain a
schema.sql
, which is the authoritative schema for my DB. Then, I'd like to runmigra postgresql:///prod-db schema.sql
to generate the statements which must be run for DBprod-db
to match schema.sql.