Commit e3c4947e authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Add migrations

parent df51a3d5
class CreateBoardFiltersTable < ActiveRecord::Migration
DOWNTIME = false
def up
create_table :board_filters do |t|
t.integer :board_id, null: false, index: true
t.integer :milestone_id, index: true
t.integer :weight, index: true
t.integer :author_id, index: true
t.integer :assignee_id, index: true
end
add_foreign_key :board_filters, :boards, column: :board_id, on_delete: :cascade
add_foreign_key :board_filters, :milestones, column: :milestone_id, on_delete: :nullify
add_foreign_key :board_filters, :users, column: :author_id, on_delete: :nullify
add_foreign_key :board_filters, :users, column: :assignee_id, on_delete: :nullify
end
def down
drop_table :board_filters
end
end
class GenerateBoardFilters < ActiveRecord::Migration
DOWNTIME = false
def up
# Sub-query executed on production
# https://gitlab.com/gitlab-com/infrastructure/issues/2839#note_41023984
execute <<-SQL
INSERT INTO board_filters(board_id, milestone_id)
SELECT id as board_id, milestone_id FROM boards
WHERE (boards.milestone_id IS NOT NULL);
SQL
end
def down
execute <<-SQL
DELETE FROM board_filters;
SQL
end
end
class CreateBoardFilterLabels < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :board_filter_labels do |t|
t.integer :board_filter_id, null: false, index: true
t.integer :label_id, null: false, index: true
end
add_foreign_key :board_filter_labels, :board_filters, column: :board_filter_id, on_delete: :cascade
add_foreign_key :board_filter_labels, :labels, column: :label_id, on_delete: :cascade
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170918223303) do
ActiveRecord::Schema.define(version: 20170921203824) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -214,6 +214,28 @@ ActiveRecord::Schema.define(version: 20170918223303) do
add_index "award_emoji", ["awardable_type", "awardable_id"], name: "index_award_emoji_on_awardable_type_and_awardable_id", using: :btree
add_index "award_emoji", ["user_id", "name"], name: "index_award_emoji_on_user_id_and_name", using: :btree
create_table "board_filter_labels", force: :cascade do |t|
t.integer "board_filter_id", null: false
t.integer "label_id", null: false
end
add_index "board_filter_labels", ["board_filter_id"], name: "index_board_filter_labels_on_board_filter_id", using: :btree
add_index "board_filter_labels", ["label_id"], name: "index_board_filter_labels_on_label_id", using: :btree
create_table "board_filters", force: :cascade do |t|
t.integer "board_id", null: false
t.integer "milestone_id"
t.integer "weight"
t.integer "author_id"
t.integer "assignee_id"
end
add_index "board_filters", ["assignee_id"], name: "index_board_filters_on_assignee_id", using: :btree
add_index "board_filters", ["author_id"], name: "index_board_filters_on_author_id", using: :btree
add_index "board_filters", ["board_id"], name: "index_board_filters_on_board_id", using: :btree
add_index "board_filters", ["milestone_id"], name: "index_board_filters_on_milestone_id", using: :btree
add_index "board_filters", ["weight"], name: "index_board_filters_on_weight", using: :btree
create_table "boards", force: :cascade do |t|
t.integer "project_id"
t.datetime "created_at", null: false
......@@ -2046,6 +2068,12 @@ ActiveRecord::Schema.define(version: 20170918223303) do
add_foreign_key "approvals", "merge_requests", name: "fk_310d714958", on_delete: :cascade
add_foreign_key "approver_groups", "namespaces", column: "group_id", on_delete: :cascade
add_foreign_key "board_filter_labels", "board_filters", on_delete: :cascade
add_foreign_key "board_filter_labels", "labels", on_delete: :cascade
add_foreign_key "board_filters", "boards", on_delete: :cascade
add_foreign_key "board_filters", "milestones", on_delete: :nullify
add_foreign_key "board_filters", "users", column: "assignee_id", on_delete: :nullify
add_foreign_key "board_filters", "users", column: "author_id", on_delete: :nullify
add_foreign_key "boards", "namespaces", column: "group_id", name: "fk_1e9a074a35", on_delete: :cascade
add_foreign_key "boards", "projects", name: "fk_f15266b5f9", on_delete: :cascade
add_foreign_key "chat_teams", "namespaces", on_delete: :cascade
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment