Skip to content

Commit

Permalink
Also match custom default tenant on PSQL_DUMP_BLACKLISTED_STATEMENTS (r…
Browse files Browse the repository at this point in the history
…ails-on-services#293)

* Add failing spec creating tenant with a default tenant

* Make PSQL_DUMP_BLACKLISTED_STATEMENTS work with a default tenant

---------

Co-authored-by: Mauricio Novelo <[email protected]>
  • Loading branch information
rbngzlv and mnovelo authored Oct 30, 2024
1 parent 4a58bb3 commit ec5a9bc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/apartment/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class PostgresqlSchemaFromSqlAdapter < PostgresqlSchemaAdapter
/SET row_security/i, # new in postgresql 9.5
/SET idle_in_transaction_session_timeout/i, # new in postgresql 9.6
/SET default_table_access_method/i, # new in postgresql 12
/CREATE SCHEMA public/i,
/COMMENT ON SCHEMA public/i,
/CREATE SCHEMA/i,
/COMMENT ON SCHEMA/i,
/SET transaction_timeout/i, # new in postgresql 17

].freeze
Expand Down
21 changes: 21 additions & 0 deletions spec/examples/schema_adapter_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@

after { subject.drop(db) }
end

context 'with a default_tenant', default_tenant: true do
let(:from_default_tenant) { 'new_from_custom_default_tenant' }

before do
subject.create(from_default_tenant)
end

after do
subject.drop(from_default_tenant)
end

it 'should correctly create the new schema' do
expect(tenant_names).to include(from_default_tenant)
end

it 'should load schema.rb to new schema' do
connection.schema_search_path = from_default_tenant
expect(connection.tables).to include('users')
end
end
end

describe '#drop' do
Expand Down
4 changes: 3 additions & 1 deletion spec/support/contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
let(:default_tenant) { Apartment::Test.next_db }

before do
Apartment::Test.create_schema(default_tenant)
# create a new tenant using apartment itself instead of Apartment::Test.create_schema
# so the default tenant also have the tables used in tests
Apartment::Tenant.create(default_tenant)
Apartment.default_tenant = default_tenant
end

Expand Down

0 comments on commit ec5a9bc

Please sign in to comment.