lib/pgslice.rb in pgslice-0.1.6 vs lib/pgslice.rb in pgslice-0.1.7

- old
+ new

@@ -74,24 +74,24 @@ SQL unless options[:no_partition] sql_format = SQL_FORMAT[period.to_sym] queries << <<-SQL - CREATE FUNCTION #{trigger_name}() - RETURNS trigger AS $$ - BEGIN - EXECUTE 'INSERT INTO #{table}_' || to_char(NEW.#{column}, '#{sql_format}') || ' VALUES ($1.*)' USING NEW; - RETURN NULL; - END; - $$ LANGUAGE plpgsql; +CREATE FUNCTION #{trigger_name}() + RETURNS trigger AS $$ + BEGIN + EXECUTE 'INSERT INTO #{table}_' || to_char(NEW.#{column}, '#{sql_format}') || ' VALUES ($1.*)' USING NEW; + RETURN NULL; + END; + $$ LANGUAGE plpgsql; SQL queries << <<-SQL - CREATE TRIGGER #{trigger_name} - BEFORE INSERT ON #{intermediate_table} - FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}(); - SQL +CREATE TRIGGER #{trigger_name} + BEFORE INSERT ON #{intermediate_table} + FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}(); + SQL end run_queries(queries) end @@ -158,15 +158,17 @@ def fill table = arguments.first abort "Usage: pgslice fill <table>" if arguments.length != 1 + source_table = options[:source_table] + if options[:swapped] - source_table = retired_name(table) + source_table ||= retired_name(table) dest_table = table else - source_table = table + source_table ||= table dest_table = intermediate_name(table) end abort "Table not found: #{source_table}" unless table_exists?(source_table) abort "Table not found: #{dest_table}" unless table_exists?(dest_table) @@ -279,19 +281,19 @@ def parse_args(args) opts = Slop.parse(args) do |o| o.boolean "--intermediate" o.boolean "--swapped" - o.boolean "--debug" o.float "--sleep" o.integer "--future", default: 0 o.integer "--past", default: 0 o.integer "--batch-size", default: 10000 o.boolean "--dry-run", default: false o.boolean "--no-partition", default: false o.integer "--start" o.string "--url" + o.string "--source-table" o.on "-v", "--version", "print the version" do log PgSlice::VERSION @exit = true end end @@ -340,10 +342,10 @@ connection.exec_params(query, params).to_a end def run_queries(queries) connection.transaction do - execute("SET client_min_messages TO warning") + execute("SET client_min_messages TO warning") unless options[:dry_run] log_sql "BEGIN;" log_sql queries.each do |query| log_sql query log_sql