diff options
-rw-r--r-- | db/migrate/098_fix_public_body_translations.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/db/migrate/098_fix_public_body_translations.rb b/db/migrate/098_fix_public_body_translations.rb new file mode 100644 index 000000000..9bcefb1c0 --- /dev/null +++ b/db/migrate/098_fix_public_body_translations.rb @@ -0,0 +1,35 @@ +# The PublicBody model class had a bug that meant the +# translations for first_letter and publication_scheme +# were not being correctly populated. +# +# This migration fixes up the data to correct this. +# +# Note that the "update ... from" syntax is a Postgres +# extension to SQL. + +class FixPublicBodyTranslations < ActiveRecord::Migration + def self.up + execute <<-SQL + update public_body_translations + set first_letter = upper(substr(name, 1, 1)) + where first_letter is null + ; + SQL + + execute <<-SQL + update public_body_translations + set publication_scheme = public_bodies.publication_scheme + from public_bodies + where public_body_translations.public_body_id = public_bodies.id + and public_body_translations.publication_scheme is null + ; + SQL + end + + def self.down + # This is a bug-fix migration, that does not involve a schema change. + # It doesn't make sense to reverse it. + end +end + + |