rails-on-services / apartment

Database multi-tenancy for Rack (and Rails) applications
388 stars 159 forks source link

parallel_migration_threads of anything greater than 1 raises ActiveRecord::ConcurrentMigrationError #298

Closed jwg2s closed 3 weeks ago

jwg2s commented 1 month ago

Steps to reproduce

Expected behavior

Actual behavior

Cannot run migrations because another migration process is currently running.



## System configuration

<!-- Please let us know as far as you can. -->

* Database: Postgres v14.12

* Apartment version: Happens regardless of `ros-apartment` version, but confirmed on `3.1.0` and `2.11.0`

* Apartment config (in `config/initializers/apartment.rb` or so):

  * `use_schemas`: `true`
  * `parallel_migration_threads`: `4`

* Rails (or ActiveRecord) version: `6.1.7.9`

* Ruby version: `3.1.4`
mnovelo commented 4 weeks ago

@jwg2s I need to update our README that parallel migrations won't work unless you implement your own schema-aware advisory locks for migrations. I'm seeking advise for how to advise users who want to use parallel migrations https://github.com/rails/rails/pull/43500#issuecomment-2447817077

mnovelo commented 4 weeks ago

@jwg2s try disabling advisory_locks as noted here https://blog.saeloun.com/2019/09/09/rails-6-disable-advisory-locks/

jwg2s commented 3 weeks ago

Thanks, @mnovelo - that worked locally so we're unblocked on at least playing around with it. Curious - do you have a functional example of schema-aware advisory locks anywhere?

mnovelo commented 3 weeks ago

Glad that worked for y'all, at least locally @jwg2s .

I do not have a functional example of schema-aware advisory locks. IMHO, I don't think they're any safer than removing advisory locks completely, so they're not worth implementing. If someone else does, I'd be happy to include it in a wiki or in the README.

I'll mark this issue as closed for now.