diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-14 20:38:57 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-14 20:38:57 +0300 |
commit | 13af7de9411ef20fcab00f7c5d7cdc6b90dbd4b7 (patch) | |
tree | 31876b6aa09c0c838ec3838aa0072293b3a0f0e6 /db | |
parent | 8210d813812571b479d630ff61410347f8ebeb5b (diff) | |
download | gitlab-ce-13af7de9411ef20fcab00f7c5d7cdc6b90dbd4b7.tar.gz |
Fix migration and association for new members table
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20140914113604_add_members_table.rb | 5 | ||||
-rw-r--r-- | db/migrate/20140914145549_migrate_to_new_members_model.rb | 11 | ||||
-rw-r--r-- | db/migrate/20140914145549_migrate_to_newmembers_model.rb | 31 | ||||
-rw-r--r-- | db/migrate/20140914173417_remove_old_member_tables.rb | 26 | ||||
-rw-r--r-- | db/schema.rb | 31 |
5 files changed, 48 insertions, 56 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 diff --git a/db/schema.rb b/db/schema.rb index 41ae717c670..4e249caa022 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140914145549) do +ActiveRecord::Schema.define(version: 20140914173417) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -141,6 +141,11 @@ ActiveRecord::Schema.define(version: 20140914145549) do t.datetime "updated_at" end + add_index "members", ["access_level"], name: "index_members_on_access_level", using: :btree + add_index "members", ["source_id", "source_type"], name: "index_members_on_source_id_and_source_type", using: :btree + add_index "members", ["type"], name: "index_members_on_type", using: :btree + add_index "members", ["user_id"], name: "index_members_on_user_id", using: :btree + create_table "merge_request_diffs", force: true do |t| t.string "state" t.text "st_commits" @@ -374,30 +379,6 @@ ActiveRecord::Schema.define(version: 20140914145549) do add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index "users", ["username"], name: "index_users_on_username", using: :btree - create_table "users_groups", force: true do |t| - t.integer "group_access", null: false - t.integer "group_id", null: false - t.integer "user_id", null: false - t.datetime "created_at" - t.datetime "updated_at" - t.integer "notification_level", default: 3, null: false - end - - add_index "users_groups", ["user_id"], name: "index_users_groups_on_user_id", using: :btree - - create_table "users_projects", force: true do |t| - t.integer "user_id", null: false - t.integer "project_id", null: false - t.datetime "created_at" - t.datetime "updated_at" - t.integer "project_access", default: 0, null: false - t.integer "notification_level", default: 3, null: false - end - - add_index "users_projects", ["project_access"], name: "index_users_projects_on_project_access", using: :btree - add_index "users_projects", ["project_id"], name: "index_users_projects_on_project_id", using: :btree - add_index "users_projects", ["user_id"], name: "index_users_projects_on_user_id", using: :btree - create_table "users_star_projects", force: true do |t| t.integer "project_id", null: false t.integer "user_id", null: false |