Class: DatabaseTransform::Schema
- Inherits:
-
Object
- Object
- DatabaseTransform::Schema
- Extended by:
- SchemaModelStore, SchemaTables
- Defined in:
- lib/database_transform/schema.rb
Class Method Summary collapse
-
.transform_table(source_table, args = {}, &proc) ⇒ Object
Transforms a table from the source database to the new database.
Instance Method Summary collapse
-
#transform! ⇒ Void
Runs the transform.
Methods included from SchemaModelStore
Methods included from SchemaTables
Class Method Details
.transform_table(source_table, args = {}, &proc) ⇒ Object
Transforms a table from the source database to the new database.
Specify the source table to get entries from; a proc with the transform steps can be specified.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/database_transform/schema.rb', line 15 def self.transform_table(source_table, args = {}, &proc) raise ArgumentError.new if source_table.nil? raise DatabaseTransform::DuplicateError.new(source_table) if tables.has_key?(source_table) source_table, args[:to] = prepare_models(source_table, args[:to]) transform = DatabaseTransform::SchemaTable.new(source_table, args[:to], args[:default_scope]) tables[source_table] = { depends: args[:depends] || [], transform: transform } transform.instance_eval(&proc) if proc end |
Instance Method Details
#transform! ⇒ Void
Runs the transform.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/database_transform/schema.rb', line 83 def transform! # The tables have dependencies; we must run them in order. transformed = Set.new queue = Set.new(tables.keys) # We try to run all the transforms we can until no more can be run. # If no more can run and the input queue is empty, we are done. # If no more can run and the input queue is not empty, we have a dependency cycle. begin transformed_this_pass = transform_pass(transformed, queue) fail DatabaseTransform::UnsatisfiedDependencyError.new(queue.to_a) if transformed_this_pass.empty? && !queue.empty? queue -= transformed_this_pass transformed += transformed_this_pass end until queue.empty? end |