Commit d8ed7894 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add table for the design<->version relation

This replaces the single design a version can belong_to a setup
where a version can belong to multiple designs.

The constraints should enforce that we only create a single version,
and only one row in the table linking them to a design.
parent 3b32dfc7
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190328210840) do
ActiveRecord::Schema.define(version: 20190403161806) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -1042,14 +1042,19 @@ ActiveRecord::Schema.define(version: 20190328210840) do
t.integer "issue_id", null: false
t.string "filename", null: false
t.index ["issue_id", "filename"], name: "index_design_management_designs_on_issue_id_and_filename", unique: true, using: :btree
t.index ["issue_id"], name: "index_design_management_designs_on_issue_id", unique: true, using: :btree
t.index ["project_id"], name: "index_design_management_designs_on_project_id", using: :btree
end
create_table "design_management_designs_versions", id: false, force: :cascade do |t|
t.bigint "design_id", null: false
t.bigint "version_id", null: false
t.index ["design_id", "version_id"], name: "design_management_designs_versions_uniqueness", unique: true, using: :btree
t.index ["design_id"], name: "index_design_management_designs_versions_on_design_id", using: :btree
t.index ["version_id"], name: "index_design_management_designs_versions_on_version_id", using: :btree
end
create_table "design_management_versions", id: :bigserial, force: :cascade do |t|
t.bigint "design_management_design_id", null: false
t.binary "sha", null: false
t.index ["design_management_design_id"], name: "index_design_management_versions_on_design_management_design_id", using: :btree
t.index ["sha"], name: "index_design_management_versions_on_sha", unique: true, using: :btree
end
......@@ -3475,7 +3480,8 @@ ActiveRecord::Schema.define(version: 20190328210840) do
add_foreign_key "deployments", "projects", name: "fk_b9a3851b82", on_delete: :cascade
add_foreign_key "design_management_designs", "issues", on_delete: :cascade
add_foreign_key "design_management_designs", "projects", on_delete: :cascade
add_foreign_key "design_management_versions", "design_management_designs", on_delete: :cascade
add_foreign_key "design_management_designs_versions", "design_management_designs", column: "design_id", on_delete: :cascade
add_foreign_key "design_management_designs_versions", "design_management_versions", column: "version_id", on_delete: :cascade
add_foreign_key "draft_notes", "merge_requests", on_delete: :cascade
add_foreign_key "draft_notes", "users", column: "author_id", on_delete: :cascade
add_foreign_key "elasticsearch_indexed_namespaces", "namespaces", on_delete: :cascade
......
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddDesignManagementDesignsVersions < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index", "remove_concurrent_index" or
# "add_column_with_default" you must disable the use of transactions
# as these methods can not run in an existing transaction.
# When using "add_concurrent_index" or "remove_concurrent_index" methods make sure
# that either of them is the _only_ method called in the migration,
# any other changes should go in a separate migration.
# This ensures that upon failure _only_ the index creation or removing fails
# and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def change
create_table(:design_management_designs_versions, id: false) do |t|
t.references :design,
null: false,
type: :bigint,
foreign_key: {
on_delete: :cascade,
to_table: :design_management_designs
}
t.references :version,
null: false,
type: :bigint,
foreign_key: {
on_delete: :cascade,
to_table: :design_management_versions
}
end
add_index :design_management_designs_versions,
[:design_id, :version_id],
unique: true, name: "design_management_designs_versions_uniqueness"
end
end
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class UpdateDesignsIndex < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
remove_concurrent_index :design_management_designs, :issue_id, unique: true
end
def down
add_concurrent_index :design_management_designs, :issue_id, unique: true
end
end
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class RemoveDesignIdFromDesignVersions < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
remove_foreign_key :design_management_versions, :design_management_designs
remove_column(:design_management_versions, :design_management_design_id)
end
def down
add_column(:design_management_versions, :design_management_design_id, :bigint)
add_concurrent_foreign_key :design_management_versions, :design_management_designs, column: :design_management_design_id
end
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