Skip to content

Commit

Permalink
[#123] check if there is an open transaction and if yes, dont create …
Browse files Browse the repository at this point in the history
…a new one
  • Loading branch information
rpbaltazar committed Dec 15, 2020
1 parent b0a4983 commit 5812824
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/apartment/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ def tenant_exists?(tenant)
end

def create_tenant_command(conn, tenant)
schema = %(BEGIN;
CREATE SCHEMA "#{tenant}";
COMMIT;)

conn.execute(schema)
# NOTE: This was causing some tests to fail because of the database strategy for rspec
if ActiveRecord::Base.connection.open_transactions > 0
conn.execute(%(CREATE SCHEMA "#{tenant}"))
else
schema = %(BEGIN;
CREATE SCHEMA "#{tenant}";
COMMIT;)

conn.execute(schema)
end
rescue *rescuable_exceptions => e
rollback_transaction(conn)
raise e
Expand Down

0 comments on commit 5812824

Please sign in to comment.