Class: DbSchema::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/db_schema/normalizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, connection) ⇒ Normalizer

Returns a new instance of Normalizer.



7
8
9
10
# File 'lib/db_schema/normalizer.rb', line 7

def initialize(schema, connection)
  @schema     = schema
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/db_schema/normalizer.rb', line 5

def connection
  @connection
end

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/db_schema/normalizer.rb', line 5

def schema
  @schema
end

Instance Method Details

#normalize_tablesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/db_schema/normalizer.rb', line 12

def normalize_tables
  connection.transaction do
    create_extensions!
    create_enums!
    create_temporary_tables!
    normalized_tables = read_temporary_tables

    schema.tables = schema.tables.map do |table|
      if table.has_expressions?
        normalized_tables.fetch(table.name)
      else
        table
      end
    end

    raise Sequel::Rollback
  end
end