Class: PGTrunk::Operations::Tables::CreateTable

Inherits:
PGTrunk::Operation show all
Defined in:
lib/pg_trunk/operations/tables/create_table.rb

Overview

When dealing with tables we're only interested in dumping tables one-by-one to enable other operations in between tables.

We doesn't overload the method create_table, but keep the original implementation unchanged. That's why neither to_sql, invert or generates_object are necessary.

While we rely on the original implementation, there are some differences in a way we fetching tables and dumping them to the schema:

  • we extracting both qualified +name+ and +oid+ for every table, and checking them against the content of pg_trunk;
  • we wrap every table new_name this class for dependencies resolving;
  • we don't keep indexes and check constraints inside the table definitions because they can depend on functions which, in turn, can depend on tables.

Instance Method Summary collapse

Methods included from PGTrunk::Operation::SQLHelpers

#quote

Methods included from PGTrunk::Operation::RubyHelpers

#dump, #to_a, #to_opts

Methods included from PGTrunk::Operation::Inversion

#invert!, #irreversible!

Methods included from PGTrunk::Operation::Validations

#error_messages

Methods included from PGTrunk::Operation::Attributes

#attributes, #initialize

Instance Method Details

#to_rubyObject

Instead of defining +ruby_snippet+, we overload the +to_ruby+ to rely on the original implementation.

We overloaded the +ActiveRecord::SchemaDumper+ methods +indexes_in_create+ and +check_constraints_in_create+ so that they do nothing to exclude indexes and constraints from a table definition.

See Also:

  • module (in `core/railtie`).


52
53
54
55
56
# File 'lib/pg_trunk/operations/tables/create_table.rb', line 52

def to_ruby
  stream = StringIO.new
  PGTrunk.dumper.send(:table, name.lean, stream)
  unindent(stream.string)
end