Module: PGTrunk::SchemaDumper

Defined in:
lib/pg_trunk/core/railtie/schema_dumper.rb

Overview

Overloads methods defined in ActiveRecord::SchemaDumper to redefine how various objects must be dumped.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.operationsObject



9
10
11
# File 'lib/pg_trunk/core/railtie/schema_dumper.rb', line 9

def operations
  @operations ||= []
end

.register(operation) ⇒ Object



13
14
15
# File 'lib/pg_trunk/core/railtie/schema_dumper.rb', line 13

def register(operation)
  operations << operation unless operations.include?(operation)
end

Instance Method Details

#dump(stream) ⇒ Object

Here we totally redefining the way a schema is dumped.

In Rails every table definition is dumped as an add_table creator including all its columns, indexes, type casts and foreign keys.

In some circumstances, these objects can have inter-dependencies with others (like functions, custom types and constraints). For example, we could define a function getting table raw as an argument, and then use this function to define check constraint for the table. In this case we must insert the definition of the function between the table's and constraint's ones.

That's why we can neither rely on the method, defined in ActiveRecord nor reuse it through fallback to super like both Scenic and F(x) do. Instead of it, we fetch object definitions from the database, and then resolve their inter-dependencies.



34
35
36
37
38
39
40
41
# File 'lib/pg_trunk/core/railtie/schema_dumper.rb', line 34

def dump(stream)
  pg_trunk_register_custom_types
  header(stream)
  extensions(stream)
  pg_trunk_objects(stream)
  trailer(stream)
  stream
end