Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Migrate globalize data #2986

Merged
merged 7 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't abort the migration if the simulation fails
We think aborting the migration will generate more headaches to system
administrators, who will have to manually check and fix every invalid
record before anything can be migrated.
  • Loading branch information
javierm committed Oct 23, 2018
commit 934bce5932ffcb6f9c1de047897a42de7b3e4eb3
11 changes: 7 additions & 4 deletions lib/tasks/globalize.rake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace :globalize do
begin
record.save!
rescue ActiveRecord::RecordInvalid
logger.error "Failed to save #{model_class} with id #{record.id}"
logger.warn "Failed to save #{model_class} with id #{record.id}"
@errored = true
end
end
Expand All @@ -68,17 +68,20 @@ namespace :globalize do
end

if errored?
logger.error "Simulation failed! Please check the errors and solve them before proceeding."
raise "Simulation failed!"
logger.warn "Some database records will not be migrated"
else
logger.info "Migrate data simulation ended successfully"
end
end

desc "Migrates existing data to translation tables"
task migrate_data: :simulate_migrate_data do
task migrate_data: :environment do
logger.info "Starting data migration"
migrate_data
logger.info "Finished data migration"

if errored?
logger.warn "Some database records couldn't be migrated; please check the log messages"
end
end
end
9 changes: 5 additions & 4 deletions spec/lib/tasks/globalize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
end

let :run_rake_task do
Rake::Task["globalize:simulate_migrate_data"].reenable
Rake::Task["globalize:migrate_data"].reenable
Rake.application.invoke_task "globalize:migrate_data"
end
Expand Down Expand Up @@ -134,14 +133,16 @@
end
end

it "simulates the task and aborts without creating any translations" do
it "ignores invalid data and migrates valid data" do
expect(valid_process).to be_valid
expect(invalid_process).not_to be_valid

expect { run_rake_task }.to raise_exception("Simulation failed!")
run_rake_task

expect(Legislation::Process::Translation.count).to eq 0
expect(valid_process.translations.count).to eq 1
expect(valid_process.reload.title).to eq "Title"

expect(invalid_process.translations.count).to eq 0
expect(invalid_process.reload.title).to eq ""
end
end
Expand Down