Skip to content

Commit

Permalink
Out put sequencer class name to log
Browse files Browse the repository at this point in the history
  • Loading branch information
hirocaster committed Nov 6, 2015
1 parent ba39b65 commit f419db5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/active_record/sharding/sequencer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def next_sequence_id
end

def execute_sql(last_insert_id_args)
connection = sequencer_repository.fetch(sequencer_name).connection
connection.execute "UPDATE `#{sequencer_config.table_name}` SET id = LAST_INSERT_ID(#{last_insert_id_args})"
res = connection.execute "SELECT LAST_INSERT_ID()"
sequencer_klass = sequencer_repository.fetch(sequencer_name)
connection = sequencer_klass.connection
connection.execute "UPDATE `#{sequencer_config.table_name}` SET id = LAST_INSERT_ID(#{last_insert_id_args})", sequencer_klass.name
res = connection.execute "SELECT LAST_INSERT_ID()", sequencer_klass.name
new_id = res.first.first.to_i
new_id
end
Expand Down
6 changes: 6 additions & 0 deletions spec/active_record/sharding/sequencer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def self.name
expect(current_id).to be_a_kind_of Fixnum
expect(model.current_sequence_id).to eq current_id
end

it "output class name to log" do
sequencer_klass = model.sequencer_repository.fetch(:user)
expect(sequencer_klass.connection).to receive(:execute).with(anything, "User::SequencerForTestUserSequencer").and_return([[0]]).twice
model.current_sequence_id
end
end

describe '#next_sequence_id' do
Expand Down

0 comments on commit f419db5

Please sign in to comment.