Skip to content

Instantly share code, notes, and snippets.

@thbar
Created December 22, 2008 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbar/39191 to your computer and use it in GitHub Desktop.
Save thbar/39191 to your computer and use it in GitHub Desktop.
Extra "etl_execution" migrations for ActiveWarehouse-ETL
Index: vendor/activewarehouse-etl/lib/etl/execution/migration.rb
===================================================================
--- vendor/activewarehouse-etl/lib/etl/execution/migration.rb (revision 765)
+++ vendor/activewarehouse-etl/lib/etl/execution/migration.rb (working copy)
@@ -8,11 +8,17 @@
def migrate
connection.initialize_schema_information
v = connection.select_value("SELECT version FROM #{schema_info_table_name}").to_i
- v.upto(target - 1) do |i|
- __send__("migration_#{i+1}".to_sym)
+ v.upto(target - 1) do |i|
+ puts "Migrating... #{i}"
+ registered_migrations[i].call(connection)
update_schema_info(i+1)
end
end
+
+ def register_migration(&block)
+ registered_migrations << block
+ end
+
protected
# Get the schema info table name
def schema_info_table_name
@@ -27,42 +33,15 @@
# Get the final target version number
def target
- 3
+ registered_migrations.size
end
private
- def migration_1 #:nodoc:
- connection.create_table :jobs do |t|
- t.column :control_file, :string, :null => false
- t.column :created_at, :datetime, :null => false
- t.column :completed_at, :datetime
- t.column :status, :string
- end
- connection.create_table :records do |t|
- t.column :control_file, :string, :null => false
- t.column :natural_key, :string, :null => false
- t.column :crc, :string, :null => false
- t.column :job_id, :integer, :null => false
- end
- end
- def migration_2 #:nodoc:
- connection.add_index :records, :control_file
- connection.add_index :records, :natural_key
- connection.add_index :records, :job_id
+ def registered_migrations
+ @registered_migrations ||= []
end
- def migration_3 #:nodoc:
- connection.create_table :batches do |t|
- t.column :batch_file, :string, :null => false
- t.column :created_at, :datetime, :null => false
- t.column :completed_at, :datetime
- t.column :status, :string
- end
- connection.add_column :jobs, :batch_id, :integer
- connection.add_index :jobs, :batch_id
- end
-
# Update the schema info table, setting the version value
def update_schema_info(version)
connection.update("UPDATE #{schema_info_table_name} SET version = #{version}")
@@ -71,3 +50,35 @@
end
end
end
+
+ETL::Execution::Migration.register_migration do |connection|
+ connection.create_table :jobs do |t|
+ t.column :control_file, :string, :null => false
+ t.column :created_at, :datetime, :null => false
+ t.column :completed_at, :datetime
+ t.column :status, :string
+ end
+ connection.create_table :records do |t|
+ t.column :control_file, :string, :null => false
+ t.column :natural_key, :string, :null => false
+ t.column :crc, :string, :null => false
+ t.column :job_id, :integer, :null => false
+ end
+end
+
+ETL::Execution::Migration.register_migration do |connection|
+ connection.add_index :records, :control_file
+ connection.add_index :records, :natural_key
+ connection.add_index :records, :job_id
+end
+
+ETL::Execution::Migration.register_migration do |connection|
+ connection.create_table :batches do |t|
+ t.column :batch_file, :string, :null => false
+ t.column :created_at, :datetime, :null => false
+ t.column :completed_at, :datetime
+ t.column :status, :string
+ end
+ connection.add_column :jobs, :batch_id, :integer
+ connection.add_index :jobs, :batch_id
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment