Class: DbSchema::Normalizer
- Inherits:
-
Object
- Object
- DbSchema::Normalizer
- Defined in:
- lib/db_schema/normalizer.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema, connection) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #normalize_tables ⇒ Object
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/db_schema/normalizer.rb', line 5 def connection @connection end |
#schema ⇒ Object (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_tables ⇒ Object
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 |