influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.67k stars 463 forks source link

Dump schema after every tenant migration #553

Open shterrett opened 6 years ago

shterrett commented 6 years ago

With an existing tenant in our database, the db/structure.sql file is not updated with migrations for the tenant(s) the first time they're run. We're having to run the migrations a second time so that the db/structure.sql accurately reflects the changes to the database.

This change dumps the schema after every tenant, overwriting the existing file as usual, so that when all the migrations are complete, the schema will be completely up-to-date. The schema is dumped after each tenant rather than after all the migrations in case one of the tenants fails to migrate - the schema will at least continue to represent the current state of the database.

btagliani commented 6 years ago

Same here, I'm having to run the migrations a second time so that the db schemas reflect the changes to the database.

chris-bridj commented 6 years ago

Just applying a bump to this – could use this fix in master so I don't have to reference this branch from my project.

btagliani commented 5 years ago

@mikecmpbll @meganemura Hi guys, sorry to bother, but could someone review this changes please? thanks!