Ignore failure in data-migration part of old schema migration.
authorTom Clegg <tom@clinicalfuture.com>
Fri, 27 Sep 2013 04:26:28 +0000 (00:26 -0400)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 27 Sep 2013 04:32:08 +0000 (00:32 -0400)
The migration should succeed if the Metadatum model did not exist in
the version of the project that was used to run the migration.

services/api/db/migrate/20130118002239_rename_metadata_attributes.rb

index 1f7af58d32854f1a149c34e3fd38b96a20117ae3..deaa35c256de08dbdf4b0101962eea5adedb1c6b 100644 (file)
@@ -9,18 +9,24 @@ class RenameMetadataAttributes < ActiveRecord::Migration
     add_index :metadata, :head_kind
     add_index :metadata, :tail
     add_index :metadata, :tail_kind
-    Metadatum.where('head like ?', 'orvos#%').each do |m|
-      kind_uuid = m.head.match /^(orvos\#.*)\#([-0-9a-z]+)$/
-      if kind_uuid
-        m.update_attributes(head_kind: kind_uuid[1],
-                            head: kind_uuid[2])
+    begin
+      Metadatum.where('head like ?', 'orvos#%').each do |m|
+        kind_uuid = m.head.match /^(orvos\#.*)\#([-0-9a-z]+)$/
+        if kind_uuid
+          m.update_attributes(head_kind: kind_uuid[1],
+                              head: kind_uuid[2])
+        end
       end
+    rescue
     end
   end
 
   def down
-    Metadatum.where('head_kind is not null and head_kind <> ? and head is not null', '').each do |m|
-      m.update_attributes(head: m.head_kind + '#' + m.head)
+    begin
+      Metadatum.where('head_kind is not null and head_kind <> ? and head is not null', '').each do |m|
+        m.update_attributes(head: m.head_kind + '#' + m.head)
+      end
+    rescue
     end
     remove_index :metadata, :tail_kind
     remove_index :metadata, :tail