forked from rails-on-services/apartment
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: strip schema from sequence name
sequence_name is shared across threads because it is stored in a class ivar. This means that on threaded servers, the sequence_name might point to a different tenant, if another tenant made the switch at the right time. This race is likely the cause of rails-on-services#81 as well. This reverts commit f8eefc4.
- Loading branch information
Showing
4 changed files
with
23 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Apartment::PostgreSqlAdapterPatch | ||
def default_sequence_name(table, _column) | ||
res = super | ||
schema_prefix = "#{Apartment::Tenant.current}." | ||
if res.starts_with?(schema_prefix) && Apartment.excluded_models.none?{|m| m.constantize.table_name == table} | ||
res.delete_prefix!("#{Apartment::Tenant.current}.") | ||
end | ||
res | ||
end | ||
end | ||
|
||
require 'active_record/connection_adapters/postgresql_adapter' | ||
|
||
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | ||
include Apartment::PostgreSqlAdapterPatch | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters