Sha256: 484bd4eb31f95dda5103d1f7612afa4b4cf5313ca5d5237c9c8be24fefaeea02
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
module PgSlice class CLI desc "swap TABLE", "Swap the intermediate table with the original table" option :lock_timeout, default: "5s", desc: "Lock timeout" def swap(table) table = create_table(table) intermediate_table = table.intermediate_table retired_table = table.retired_table assert_table(table) assert_table(intermediate_table) assert_no_table(retired_table) queries = [ "ALTER TABLE #{quote_table(table)} RENAME TO #{quote_no_schema(retired_table)};", "ALTER TABLE #{quote_table(intermediate_table)} RENAME TO #{quote_no_schema(table)};" ] table.sequences.each do |sequence| queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_schema"])}.#{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_table(table)}.#{quote_ident(sequence["related_column"])};" end queries.unshift("SET LOCAL lock_timeout = '#{options[:lock_timeout]}';") if server_version_num >= 90300 run_queries(queries) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pgslice-0.5.0 | lib/pgslice/cli/swap.rb |
pgslice-0.4.8 | lib/pgslice/cli/swap.rb |
pgslice-0.4.7 | lib/pgslice/cli/swap.rb |