Skip to content

Commit

Permalink
Fix status and status:with_data rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
wildmaples committed Jun 28, 2023
1 parent ec8fbf2 commit 4f4f97d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
19 changes: 4 additions & 15 deletions lib/data_migrate/tasks/data_migrate_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ def dump_schema_after_migration?
end
end

def status(db_config)
puts "\ndatabase: #{spec_name(db_config)}\n\n"
DataMigrate::StatusService.dump(ActiveRecord::Base.connection)
def status
DataMigrate::StatusService.dump
end

def status_with_schema(db_config)
def status_with_schema
db_list_data = ActiveRecord::Base.connection.select_values(
"SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
)
Expand Down Expand Up @@ -77,7 +76,7 @@ def status_with_schema(db_config)
file_list.sort!{|a,b| "#{a[1]}_#{a[3] == 'data' ? 1 : 0}" <=> "#{b[1]}_#{b[3] == 'data' ? 1 : 0}" }

# output
puts "\ndatabase: #{spec_name(db_config)}\n\n"
puts "\ndatabase: #{ActiveRecord::Base.connection.pool.db_config.database}\n\n"
puts "#{"Status".center(8)} #{"Type".center(8)} #{"Migration ID".ljust(14)} Migration Name"
puts "-" * 60
file_list.each do |file|
Expand All @@ -91,16 +90,6 @@ def status_with_schema(db_config)
end
puts
end

private

def spec_name(db_config)
if Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
db_config.name
elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
db_config.spec_name
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/data_migrate/tasks/data_migrate_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@

it "should display data migration status" do
expect {
DataMigrate::Tasks::DataMigrateTasks.status(connection_db_config)
DataMigrate::Tasks::DataMigrateTasks.status
}.to output(/up 20091231235959 Some name/).to_stdout
end

it "should display schema and data migration status" do
expect {
DataMigrate::Tasks::DataMigrateTasks.status_with_schema(connection_db_config)
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
}.to output(match(/up data 20091231235959 Some name/)
.and match(/down schema 20131111111111 Late migration/)).to_stdout
end
Expand Down

0 comments on commit 4f4f97d

Please sign in to comment.