3 class OrderRelationMembers < ActiveRecord::Migration[4.2]
5 # add sequence column. rails won't let us define an ordering here,
6 # as defaults must be constant.
7 add_column(:relation_members, :sequence_id, :integer,
8 :default => 0, :null => false)
10 # update the sequence column with default (partial) ordering by
11 # element ID. the sequence ID is a smaller int type, so we can't
12 # just copy the member_id.
13 execute("update relation_members set sequence_id = mod(member_id, 16384)")
15 # need to update the primary key to include the sequence number,
16 # otherwise the primary key will barf when we have repeated members.
17 # mysql barfs on this anyway, so we need a single command. this may
18 # not work in postgres... needs testing.
19 alter_primary_key("relation_members", [:id, :version, :member_type, :member_id, :member_role, :sequence_id])
21 # do the same for the current tables
22 add_column(:current_relation_members, :sequence_id, :integer,
23 :default => 0, :null => false)
24 execute("update current_relation_members set sequence_id = mod(member_id, 16384)")
25 alter_primary_key("current_relation_members", [:id, :member_type, :member_id, :member_role, :sequence_id])
29 alter_primary_key("current_relation_members", [:id, :member_type, :member_id, :member_role])
30 remove_column :relation_members, :sequence_id
32 alter_primary_key("relation_members", [:id, :version, :member_type, :member_id, :member_role])
33 remove_column :current_relation_members, :sequence_id