Class: Chicago::Database::MigrationFileWriter Private
- Inherits:
-
Object
- Object
- Chicago::Database::MigrationFileWriter
- Defined in:
- lib/chicago/database/migration_file_writer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Writes Sequel migrations for the star schema
Instance Method Summary collapse
-
#initialize(db, migration_directory) ⇒ MigrationFileWriter
constructor
private
Creates a new migration file writer, given a Sequel::Database connection and a directory.
-
#migration_file ⇒ Object
private
Returns the path the migration file has been written to.
-
#write_migration_file(schema) ⇒ Object
private
Writes the migration file necessary for all defined facts and dimensions.
Constructor Details
#initialize(db, migration_directory) ⇒ MigrationFileWriter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new migration file writer, given a Sequel::Database connection and a directory. If the directory does not exist, an error will be raised.
10 11 12 13 |
# File 'lib/chicago/database/migration_file_writer.rb', line 10 def initialize(db, migration_directory) @db = db @migration_directory = migration_directory end |
Instance Method Details
#migration_file ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the path the migration file has been written to.
28 29 30 31 |
# File 'lib/chicago/database/migration_file_writer.rb', line 28 def migration_file @file ||= File.join(@migration_directory, "#{Time.now.strftime("%Y%m%d%H%M%S")}_auto_migration.rb") end |
#write_migration_file(schema) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes the migration file necessary for all defined facts and dimensions.
17 18 19 20 21 22 23 24 25 |
# File 'lib/chicago/database/migration_file_writer.rb', line 17 def write_migration_file(schema) @file = nil type_converter = TypeConverters::DbTypeConverter.for_db(@db) tables = SchemaGenerator.new(type_converter).traverse(schema) File.open(migration_file, "w") do |fh| fh.write Sequel::MigrationBuilder.new(@db).generate_migration(tables) end end |