Commit bcb5f8a2 authored by Jan Provaznik's avatar Jan Provaznik

Updated DB migration

* reordered columns
* moved fks to separate migrations
parent 9bffa830
......@@ -7,16 +7,18 @@ class CreateRequirements < ActiveRecord::Migration[6.0]
def change
create_table :requirements do |t|
t.integer :state, limit: 2, default: 1, null: false
t.timestamps_with_timezone null: false
t.integer :project_id, null: false
t.integer :author_id
t.integer :iid, null: false
t.integer :cached_markdown_version
t.references :project, null: false, index: true, foreign_key: { on_delete: :cascade }
t.references :author, index: true, foreign_key: { to_table: :users, on_delete: :nullify }
t.timestamps_with_timezone null: false
t.integer :state, limit: 2, default: 1, null: false
t.string :title, limit: 255, null: false
t.text :title_html
t.index :title
t.index :project_id
t.index :author_id
t.index :title, name: "index_requirements_on_title_trigram", using: :gin, opclass: :gin_trgm_ops
t.index :state
t.index :created_at
t.index :updated_at
......
# frozen_string_literal: true
class RequirementsAddProjectFk < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_foreign_key(:requirements, :projects, column: :project_id, on_delete: :cascade) # rubocop: disable Migration/AddConcurrentForeignKey
end
end
def down
with_lock_retries do
remove_foreign_key(:requirements, column: :project_id)
end
end
end
# frozen_string_literal: true
class RequirementsAddAuthorFk < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_foreign_key(:requirements, :users, column: :author_id, on_delete: :nullify) # rubocop: disable Migration/AddConcurrentForeignKey
end
end
def down
with_lock_retries do
remove_foreign_key(:requirements, column: :author_id)
end
end
end
......@@ -3723,13 +3723,13 @@ ActiveRecord::Schema.define(version: 2020_02_27_165129) do
end
create_table "requirements", force: :cascade do |t|
t.integer "state", limit: 2, default: 1, null: false
t.integer "iid", null: false
t.integer "cached_markdown_version"
t.bigint "project_id", null: false
t.bigint "author_id"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.integer "project_id", null: false
t.integer "author_id"
t.integer "iid", null: false
t.integer "cached_markdown_version"
t.integer "state", limit: 2, default: 1, null: false
t.string "title", limit: 255, null: false
t.text "title_html"
t.index ["author_id"], name: "index_requirements_on_author_id"
......@@ -3737,7 +3737,7 @@ ActiveRecord::Schema.define(version: 2020_02_27_165129) do
t.index ["project_id", "iid"], name: "index_requirements_on_project_id_and_iid", unique: true, where: "(project_id IS NOT NULL)"
t.index ["project_id"], name: "index_requirements_on_project_id"
t.index ["state"], name: "index_requirements_on_state"
t.index ["title"], name: "index_requirements_on_title"
t.index ["title"], name: "index_requirements_on_title_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["updated_at"], name: "index_requirements_on_updated_at"
end
......
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