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

Conversation

javierm
Copy link
Member

@javierm javierm commented Oct 23, 2018

References

Background

We forgot to migrate existing data when we created the translations tables, and so when we edit translatable fields in the administration, they seem to be empty, increasing the risk of data loss.

Objectives

Migrate existing data to the translation tables (unless we've already translated those records!) so contents show up when administrators edit contents.

Notes

⚠️ For release notes:

In order to migrate existing data, execute:
bin/rake globalize:migrate_data RAILS_ENV=production

Although we believe it's completely safe to run this task, we recommend backing up the database before executing any task which modifies its data.

This task will not migrate records which contain invalid data (for example, a banner with a blank title), which might happen if the database content has been edited manually by system administrators. You can check which records aren't migrated by checking the warnings generated by executing:
bin/rake globalize:simulate_migrate_data RAILS_ENV=production

Most of the time no records contain invalid data and the task will run without any warnings.

Globalize developers recommend removing the original columns after migrating the data, since having both original and translated columns is not supported. We might add another task dealing with this issue.

We forgot to do it when we created the translation tables, and so now we
need to make sure we don't overwrite existing translations.
This way the task to migrate the data doesn't have to be run manually if
these migrations weren't already executed.
In theory, it should never happen, but that's why exceptions exist.
This way we can check everything is OK before actually migrating the
data to the translations tables.
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.
Ruby can't have hyphens in method names, so sending something like
`record.title_pt-BR` would raise an exception.

Using globalize's `localized_attr_name_for` method fixes the bug.

Thanks Marko for the tip.
@javierm javierm merged commit e7f05a5 into master Oct 26, 2018
@javierm javierm deleted the backport-migrate_globalize_data branch October 26, 2018 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants