]> git.openstreetmap.org Git - rails.git/blobdiff - db/migrate/022_order_relation_members.rb
Postgres adapter, and make migration 022 db-agnostic
[rails.git] / db / migrate / 022_order_relation_members.rb
index e3820d4e610ce5a4cca6573f3b1293216f6755ad..5500edfcfbf4ac42e9a35e9d754dfdc049a96a47 100644 (file)
@@ -8,26 +8,26 @@ class OrderRelationMembers < ActiveRecord::Migration
     # update the sequence column with default (partial) ordering by 
     # element ID. the sequence ID is a smaller int type, so we can't
     # just copy the member_id.
     # update the sequence column with default (partial) ordering by 
     # element ID. the sequence ID is a smaller int type, so we can't
     # just copy the member_id.
-    ActiveRecord::Base.connection().execute("update relation_members set sequence_id = mod(member_id, 16384)")
+    execute("update relation_members set sequence_id = mod(member_id, 16384)")
 
     # need to update the primary key to include the sequence number, 
     # otherwise the primary key will barf when we have repeated members.
     # mysql barfs on this anyway, so we need a single command. this may
     # not work in postgres... needs testing.
 
     # need to update the primary key to include the sequence number, 
     # otherwise the primary key will barf when we have repeated members.
     # mysql barfs on this anyway, so we need a single command. this may
     # not work in postgres... needs testing.
-    ActiveRecord::Base.connection().execute("alter table relation_members drop primary key, add primary key (id, version, member_type, member_id, member_role, sequence_id)")
+    alter_primary_key("relation_members", [:id, :version, :member_type, :member_id, :member_role, :sequence_id])
 
     # do the same for the current tables
     add_column(:current_relation_members, :sequence_id, :integer,
                :default => 0, :null => false)
 
     # do the same for the current tables
     add_column(:current_relation_members, :sequence_id, :integer,
                :default => 0, :null => false)
-    ActiveRecord::Base.connection().execute("update current_relation_members set sequence_id = mod(member_id, 16384)")
-    ActiveRecord::Base.connection().execute("alter table current_relation_members drop primary key, add primary key (id, member_type, member_id, member_role, sequence_id)")
+    execute("update current_relation_members set sequence_id = mod(member_id, 16384)")
+    alter_primary_key("current_relation_members", [:id, :member_type, :member_id, :member_role, :sequence_id])
   end
 
   def self.down
   end
 
   def self.down
-    ActiveRecord::Base.connection().execute("alter table current_relation_members drop primary key, add primary key (id, member_type, member_id, member_role)")
+    alter_primary_key("current_relation_members", [:id, :member_type, :member_id, :member_role])
     remove_column :relation_members, :sequence_id
 
     remove_column :relation_members, :sequence_id
 
-    ActiveRecord::Base.connection().execute("alter table relation_members drop primary key, add primary key (id, version, member_type, member_id, member_role)")
+    alter_primary_key("relation_members", [:id, :version, :member_type, :member_id, :member_role])
     remove_column :current_relation_members, :sequence_id
   end
 end
     remove_column :current_relation_members, :sequence_id
   end
 end