diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-14 21:38:57 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-14 21:38:57 +0400 |
commit | 13af7de9411ef20fcab00f7c5d7cdc6b90dbd4b7 (patch) | |
tree | 31876b6aa09c0c838ec3838aa0072293b3a0f0e6 /db/migrate | |
parent | 8210d813812571b479d630ff61410347f8ebeb5b (diff) |
Fix migration and association for new members table
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'db/migrate')
4 files changed, 42 insertions, 31 deletions
diff --git a/db/migrate/20140914113604_add_members_table.rb b/db/migrate/20140914113604_add_members_table.rb index 1738c8dc655..d311f3033ee 100644 --- a/db/migrate/20140914113604_add_members_table.rb +++ b/db/migrate/20140914113604_add_members_table.rb @@ -10,5 +10,10 @@ class AddMembersTable < ActiveRecord::Migration t.timestamps end + + add_index :members, :type + add_index :members, :user_id + add_index :members, :access_level + add_index :members, [:source_id, :source_type] end end diff --git a/db/migrate/20140914145549_migrate_to_new_members_model.rb b/db/migrate/20140914145549_migrate_to_new_members_model.rb new file mode 100644 index 00000000000..b4f7718f26d --- /dev/null +++ b/db/migrate/20140914145549_migrate_to_new_members_model.rb @@ -0,0 +1,11 @@ +class MigrateToNewMembersModel < ActiveRecord::Migration + def up + execute "INSERT INTO members ( user_id, source_id, source_type, access_level, notification_level, type ) SELECT user_id, group_id, 'Group', group_access, notification_level, 'GroupMember' FROM users_groups" + execute "INSERT INTO members ( user_id, source_id, source_type, access_level, notification_level, type ) SELECT user_id, project_id, 'Project', project_access, notification_level, 'ProjectMember' FROM users_projects" + end + + def down + Member.delete_all + end +end + diff --git a/db/migrate/20140914145549_migrate_to_newmembers_model.rb b/db/migrate/20140914145549_migrate_to_newmembers_model.rb deleted file mode 100644 index 9c4517f95e5..00000000000 --- a/db/migrate/20140914145549_migrate_to_newmembers_model.rb +++ /dev/null @@ -1,31 +0,0 @@ -class MigrateToNewmembersModel < ActiveRecord::Migration - def up - UsersGroup.find_each(batch_size: 500) do |user_group| - GroupMember.create( - user_id: user_group.user_id, - source_type: 'Group', - source_id: user_group.group_id, - access_level: user_group.group_access, - notification_level: user_group.notification_level, - ) - - print '.' - end - - UsersProject.find_each(batch_size: 500) do |user_project| - ProjectMember.create( - user_id: user_project.user_id, - source_type: 'Project', - source_id: user_project.project_id, - access_level: user_project.project_access, - notification_level: user_project.notification_level, - ) - - print '.' - end - end - - def down - Member.destroy_all - end -end diff --git a/db/migrate/20140914173417_remove_old_member_tables.rb b/db/migrate/20140914173417_remove_old_member_tables.rb new file mode 100644 index 00000000000..408b9551dbb --- /dev/null +++ b/db/migrate/20140914173417_remove_old_member_tables.rb @@ -0,0 +1,26 @@ +class RemoveOldMemberTables < ActiveRecord::Migration + def up + drop_table :users_groups + drop_table :users_projects + end + + def down + create_table :users_groups do |t| + t.integer :group_access, null: false + t.integer :group_id, null: false + t.integer :user_id, null: false + t.integer :notification_level, null: false, default: 3 + + t.timestamps + end + + create_table :users_projects do |t| + t.integer :project_access, null: false + t.integer :project_id, null: false + t.integer :user_id, null: false + t.integer :notification_level, null: false, default: 3 + + t.timestamps + end + end +end |