influitive / apartment

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

Run migrations instead of importing via schema.rb / pg_dump #628

Open h0jeZvgoxFepBQ2C opened 4 years ago

h0jeZvgoxFepBQ2C commented 4 years ago

Since we are playing around with apartment, and after reading following blog entry https://influitive.io/our-multi-tenancy-journey-with-postgres-schemas-and-apartment-6ecda151a21f?gi=16140b70d3fa

Currently the Apartment gem uses the rails schema.rb for generating new tenants. This is a mistake. This file changes locally when running migrations, but it represents exactly what that developer has in their local database. If a feature branch (for example) has experimental database columns added, those can end up sneaking out to production if you inadvertently commit the schema.rb changes to your mainline development branch.

I wanted to ask if there is a way to just run the normal migrations (instead of executing schema.rb or import via sql/pg_dump)? I know, it's maybe not best practice, but our deployment is based on working migrations and it would fit nicely to our workflow.

If there is no possibility right now, I would maybe spend some time to create a PR for this?

sigfrid commented 4 years ago

I have the same issue due to a complex index in my migration which doesn't seem to work with the current implementation.

If you decided to create a PR, I suggest opening at https://github.com/rails-on-services/apartment since this project doesn't seem to be maintained anymore.