Closed rbngzlv closed 1 week ago
Have you solved this ? I am facing the same issue when setting custom default_tenant = 'apartment_template'
I checked a couple of projects and one of them is overriding the constant value in an initializer with a duplicate of the original array plus the following lines.
/CREATE SCHEMA #{Apartment.default_tenant}/i
/COMMENT ON SCHEMA #{Apartment.default_tenant}/i
Hi @mnovelo! I would like to know your opinion on this to see if I can help with this. Thank you!
@rbngzlv I don't see a problem with this. I'm happy to review a PR!
Steps to reproduce
Configure a
default_tenant
that isn't thepublic
default and try to create a new tenant. This fails with:Seems that the problem is raised when cloning the schema to the new one, because the
pg_dump
includes the creation of the already existing schema (the default):This doesn't happen when using
public
as the default tenant because this statements are blacklisted:https://github.com/rails-on-services/apartment/blob/c733f35bf8da44fb4d9dda8499066f1409aa4b99/lib/apartment/adapters/postgresql_adapter.rb#L160-L169
Here is where the
pg_dump
output is "sanitized":https://github.com/rails-on-services/apartment/blob/c733f35bf8da44fb4d9dda8499066f1409aa4b99/lib/apartment/adapters/postgresql_adapter.rb#L255-L263
WDYT if we move the blacklisting of the
public
statements from the constantPSQL_DUMP_BLACKLISTED_STATEMENTS
to inside thepatch_search_path
method? Any other approach?As a note, this method is doing more than patching the search path 😄 , are you open to rename the method?
Thank you.
Expected behavior
The creation of a new tenant doesn't raises any error
Actual behavior
The creation of a new tenant fails:
System configuration
Database: (Tell us what database and its version you use.) PostgreSQL 11.9
Apartment version: 2.9
Apartment config (in
config/initializers/apartment.rb
or so):use_schemas
: (true
orfalse
) trueRails (or ActiveRecord) version: Rails 6.0.3.7
Ruby version: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux-musl]