Skip to content

Commit

Permalink
Refactor sequencer database task method
Browse files Browse the repository at this point in the history
  • Loading branch information
hirocaster committed Aug 27, 2015
1 parent f272b18 commit 9b4d170
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions lib/active_record/sharding/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,45 +190,43 @@ def drop_sequencer_database(args)
end

def create_table_sequencer_database(args)
sequencer_name = sequencer_name_or_error "create_table", args
sequencer = sequencer_or_error sequencer_name

sequencer = sequencer_or_error "create_table", args
create_table_sql = "CREATE TABLE #{sequencer.table_name} (id BIGINT unsigned NOT NULL DEFAULT 0) ENGINE=MyISAM"
execute sequencer.connection_name.to_s, create_table_sql
end

def insert_initial_record_sequencer_database(args)
sequencer_name = sequencer_name_or_error "insert_initial_record", args
sequencer = sequencer_or_error sequencer_name

sequencer = sequencer_or_error "insert_initial_record", args
insert_initial_record_sql = "INSERT INTO #{sequencer.table_name} VALUES (0)"
execute sequencer.connection_name.to_s, insert_initial_record_sql
end

private

def exec_task_for_sequencer_database(task_name, args)
sequencer_name = sequencer_name_or_error task_name, args
sequencer = sequencer_or_error sequencer_name
sequencer = sequencer_or_error task_name, args
__send__ task_name, sequencer.connection_name.to_s
end

def sequencer_name_or_error(name, args)
def sequencer_or_error(task_name, args)
sequencer_name = sequencer_name_or_error task_name, args
fetch_sequencer_config sequencer_name.to_sym
rescue KeyError
$stderr.puts %(sequencer name "#{sequencer_name}" not found.)
exit
end

def sequencer_name_or_error(task_name, args)
unless sequencer_name = args[:sequencer_name]
# rubocop:disable Metrics/LineLength
$stderr.puts <<-MSG
Missing sequencer_name. Find sequencer_name via `rake active_record:sharding:info` then call `rake "active_record:sharding:sequencer#{name}[$sequencer_name]"`.
Missing sequencer_name. Find sequencer_name via `rake active_record:sharding:info` then call `rake "active_record:sharding:sequencer#{task_name}[$sequencer_name]"`.
MSG
exit
# rubocop:enable Metrics/LineLength
end
sequencer_name
end

def sequencer_or_error(sequencer_name)
fetch_sequencer_config sequencer_name.to_sym
rescue KeyError
$stderr.puts %(sequencer name "#{sequencer_name}" not found.)
exit
end
end
extend TasksForSingleSequencerTask
end # module DatabaseTasks
Expand Down

0 comments on commit 9b4d170

Please sign in to comment.