Sha256: 6d4ee1e4c2aa9f242614f3f43a6e094193325abff3e39e15eb14638b82cf204a

Contents?: true

Size: 823 Bytes

Versions: 5

Compression:

Stored size: 823 Bytes

Contents

module PgSlice
  class CLI
    desc "unswap TABLE", "Undo swap"
    def unswap(table)
      table = create_table(table)
      intermediate_table = table.intermediate_table
      retired_table = table.retired_table

      assert_table(table)
      assert_table(retired_table)
      assert_no_table(intermediate_table)

      queries = [
        "ALTER TABLE #{quote_table(table)} RENAME TO #{quote_no_schema(intermediate_table)};",
        "ALTER TABLE #{quote_table(retired_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

      run_queries(queries)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pgslice-0.6.1 lib/pgslice/cli/unswap.rb
pgslice-0.6.0 lib/pgslice/cli/unswap.rb
pgslice-0.5.0 lib/pgslice/cli/unswap.rb
pgslice-0.4.8 lib/pgslice/cli/unswap.rb
pgslice-0.4.7 lib/pgslice/cli/unswap.rb