lib/etl/execution/migration.rb in activewarehouse-etl-0.8.4 vs lib/etl/execution/migration.rb in activewarehouse-etl-0.9.0

- old
+ new

@@ -6,11 +6,14 @@ class << self # 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) { |i| __send__("migration_#{i+1}".to_sym) } + v.upto(target - 1) do |i| + __send__("migration_#{i+1}".to_sym) + update_schema_info(i+1) + end end protected # Get the schema info table name def schema_info_table_name ETL::Execution::Base.table_name_prefix + "schema_info" + @@ -22,11 +25,11 @@ @connection ||= ETL::Execution::Base.connection end # Get the final target version number def target - 2 + 3 end private def migration_1 #:nodoc: connection.create_table :jobs do |t| @@ -39,17 +42,26 @@ 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 - update_schema_info(1) end def migration_2 #:nodoc: connection.add_index :records, :control_file connection.add_index :records, :natural_key connection.add_index :records, :job_id - update_schema_info(2) + 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}")