From 57a44f2da3d2a0b59209b6c2d653d04efd0d3d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarka=20Kadlecov=C3=A1?= Date: Wed, 13 Jun 2018 18:11:10 +0200 Subject: Support todos for epics backport --- db/migrate/20180608091413_add_group_to_todos.rb | 32 +++++++++++++++++++++++++ db/schema.rb | 5 +++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180608091413_add_group_to_todos.rb (limited to 'db') diff --git a/db/migrate/20180608091413_add_group_to_todos.rb b/db/migrate/20180608091413_add_group_to_todos.rb new file mode 100644 index 00000000000..ca08de835a1 --- /dev/null +++ b/db/migrate/20180608091413_add_group_to_todos.rb @@ -0,0 +1,32 @@ +class AddGroupToTodos < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_column :todos, :group_id, :integer + add_foreign_key :todos, :namespaces, column: :group_id, on_delete: :cascade + add_concurrent_index :todos, :group_id + + change_column_null :todos, :project_id, true + end + + def down + return unless group_id_exists? + + remove_foreign_key :todos, column: :group_id + remove_index :todos, :group_id if index_exists?(:todos, :group_id) + remove_column :todos, :group_id + + execute "DELETE FROM todos WHERE project_id IS NULL" + change_column_null :todos, :project_id, false + end + + private + + def group_id_exists? + column_exists?(:todos, :group_id) + end +end diff --git a/db/schema.rb b/db/schema.rb index 0112fc726d4..504d57b8aa2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1929,7 +1929,7 @@ ActiveRecord::Schema.define(version: 20180626125654) do create_table "todos", force: :cascade do |t| t.integer "user_id", null: false - t.integer "project_id", null: false + t.integer "project_id" t.integer "target_id" t.string "target_type", null: false t.integer "author_id", null: false @@ -1939,10 +1939,12 @@ ActiveRecord::Schema.define(version: 20180626125654) do t.datetime "updated_at" t.integer "note_id" t.string "commit_id" + t.integer "group_id" end add_index "todos", ["author_id"], name: "index_todos_on_author_id", using: :btree add_index "todos", ["commit_id"], name: "index_todos_on_commit_id", using: :btree + add_index "todos", ["group_id"], name: "index_todos_on_group_id", using: :btree add_index "todos", ["note_id"], name: "index_todos_on_note_id", using: :btree add_index "todos", ["project_id"], name: "index_todos_on_project_id", using: :btree add_index "todos", ["target_type", "target_id"], name: "index_todos_on_target_type_and_target_id", using: :btree @@ -2313,6 +2315,7 @@ ActiveRecord::Schema.define(version: 20180626125654) do add_foreign_key "term_agreements", "users", on_delete: :cascade add_foreign_key "timelogs", "issues", name: "fk_timelogs_issues_issue_id", on_delete: :cascade add_foreign_key "timelogs", "merge_requests", name: "fk_timelogs_merge_requests_merge_request_id", on_delete: :cascade + add_foreign_key "todos", "namespaces", column: "group_id", on_delete: :cascade add_foreign_key "todos", "notes", name: "fk_91d1f47b13", on_delete: :cascade add_foreign_key "todos", "projects", name: "fk_45054f9c45", on_delete: :cascade add_foreign_key "todos", "users", column: "author_id", name: "fk_ccf0373936", on_delete: :cascade -- cgit v1.2.3 From 7458ca8ebb093af93c01cb61dabca15fd0c995cb Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Thu, 21 Jun 2018 08:24:03 +0200 Subject: [backend] Addressed review comments * Group filtering now includes also issues/MRs from subgroups/subprojects * fixed due_date * Also DRYed todo controller specs --- db/migrate/20180608091413_add_group_to_todos.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'db') diff --git a/db/migrate/20180608091413_add_group_to_todos.rb b/db/migrate/20180608091413_add_group_to_todos.rb index ca08de835a1..af3ee48b29d 100644 --- a/db/migrate/20180608091413_add_group_to_todos.rb +++ b/db/migrate/20180608091413_add_group_to_todos.rb @@ -7,7 +7,7 @@ class AddGroupToTodos < ActiveRecord::Migration def up add_column :todos, :group_id, :integer - add_foreign_key :todos, :namespaces, column: :group_id, on_delete: :cascade + add_concurrent_foreign_key :todos, :namespaces, column: :group_id, on_delete: :cascade add_concurrent_index :todos, :group_id change_column_null :todos, :project_id, true -- cgit v1.2.3