aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Houston <robin@lenny.robin>2011-06-15 05:40:55 +0100
committerRobin Houston <robin@lenny.robin>2011-06-15 05:40:55 +0100
commitfb5f1b3f3834dd696ae4aa6cc906244b6c23da78 (patch)
treeef4a2538c3cab7f03c9fe6f76878319632373cae
parent862fa3a14caaf202ec52bca4157a413860a894c5 (diff)
Add a migration that fixes the data problems caused by the PublicBody bug
-rw-r--r--db/migrate/098_fix_public_body_translations.rb35
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
+
+