lib/etl/execution/migration.rb in activewarehouse-etl-0.9.0 vs lib/etl/execution/migration.rb in activewarehouse-etl-0.9.1
- old
+ new
@@ -2,34 +2,42 @@
module Execution #:nodoc
# Handles migration of tables required for persistent storage of meta data
# for the ETL engine
class Migration
class << self
+ protected
+ # Get the schema info table name
+ def schema_info_table_name
+ ActiveRecord::Migrator.schema_migrations_table_name
+ end
+ alias :schema_migrations_table_name :schema_info_table_name
+
+ public
# Execute the migrations
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|
+ connection.initialize_schema_migrations_table
+ last_migration.upto(target - 1) do |i|
__send__("migration_#{i+1}".to_sym)
- update_schema_info(i+1)
+ connection.assume_migrated_upto_version(i+1)
end
end
+
protected
- # Get the schema info table name
- def schema_info_table_name
- ETL::Execution::Base.table_name_prefix + "schema_info" +
- ETL::Execution::Base.table_name_suffix
+ def last_migration
+ connection.select_values(
+ "SELECT version FROM #{schema_migrations_table_name}"
+ ).map(&:to_i).sort.last || 0
end
# Get the connection to use during migration
def connection
@connection ||= ETL::Execution::Base.connection
end
# Get the final target version number
def target
- 3
+ 4
end
private
def migration_1 #:nodoc:
connection.create_table :jobs do |t|
@@ -59,9 +67,13 @@
t.column :completed_at, :datetime
t.column :status, :string
end
connection.add_column :jobs, :batch_id, :integer
connection.add_index :jobs, :batch_id
+ end
+
+ def migration_4
+ connection.drop_table :records
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}")