Skip to content

Commit

Permalink
More reliably determine database adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Davies committed Nov 20, 2015
1 parent a506f9c commit b98beaa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/sequenced/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(record, options = {})

def set
return if id_set? || skip?
lock_table(record.class)
lock_table
record.send(:"#{column}=", next_id)
end

Expand Down Expand Up @@ -46,14 +46,14 @@ def unique?(id)

private

def lock_table(klass)
def lock_table
if postgresql?
klass.connection.execute("LOCK TABLE #{klass.table_name} IN EXCLUSIVE MODE")
record.class.connection.execute("LOCK TABLE #{record.class.table_name} IN EXCLUSIVE MODE")
end
end

def postgresql?
ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
record.class.connection.instance_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
end

def base_relation
Expand Down

0 comments on commit b98beaa

Please sign in to comment.