influitive / apartment

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

Apartment Gem dropping Tables in public schema!! :( #569

Open jimishjoban opened 5 years ago

jimishjoban commented 5 years ago

Steps to reproduce

Apartment::Tenant.create('archived')

Expected behavior

It should simply create a new schema with tables present in public.

Actual behavior

Its dropping all data/tables in public schema... Disaster!

System configuration

Ruby - ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux] Usinng PG Bouncer to connect. (if it matters)

Postgres 9.3

2.1.0

Same ditto config as gennerated...

4.1.5

Ruby - ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]

Xtinct commented 5 years ago

Do you have public schema as a part of persistent_schemas option? I had the same problem when both public and user schemas were containing table with the same name. The solution for me was to manually create schema and run migration since persistent_schemas option is not threadsafe.

byted commented 4 years ago

An alternative solution is to use config.use_sql = true in apartment.rb config file as it seems the DROP commands are caused by the algorithm that uses the schema.rb.