diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-14 15:42:24 +0300 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-16 15:35:27 +0300 |
commit | 4c1e6fd0e83ceb550ec07448d6a37e76cc25e4fa (patch) | |
tree | a997f15918ddd391133a5243a02e57761d997146 /db | |
parent | 539bdf73be4a84b1f542801a28f016808d604fe5 (diff) |
Simplify migration and add NOT NULL to project_id.
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20180305095250_create_internal_ids_table.rb | 20 | ||||
-rw-r--r-- | db/schema.rb | 4 |
2 files changed, 4 insertions, 20 deletions
diff --git a/db/migrate/20180305095250_create_internal_ids_table.rb b/db/migrate/20180305095250_create_internal_ids_table.rb index d2e79a12c0a..e972432fb98 100644 --- a/db/migrate/20180305095250_create_internal_ids_table.rb +++ b/db/migrate/20180305095250_create_internal_ids_table.rb @@ -3,33 +3,17 @@ class CreateInternalIdsTable < ActiveRecord::Migration DOWNTIME = false - disable_ddl_transaction! - def up create_table :internal_ids, id: :bigserial do |t| - t.references :project + t.references :project, null: false, foreign_key: { on_delete: :cascade } t.integer :usage, null: false t.integer :last_value, null: false - end - - unless index_exists?(:internal_ids, [:usage, :project_id]) - add_index :internal_ids, [:usage, :project_id], unique: true - end - unless foreign_key_exists?(:internal_ids, :project_id) - add_concurrent_foreign_key :internal_ids, :projects, column: :project_id, on_delete: :cascade + t.index [:usage, :project_id], unique: true end end def down drop_table :internal_ids end - - private - - def foreign_key_exists?(table, column) - foreign_keys(table).any? do |key| - key.options[:column] == column.to_s - end - end end diff --git a/db/schema.rb b/db/schema.rb index aab8ad4753e..3ff1a8754e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -867,7 +867,7 @@ ActiveRecord::Schema.define(version: 20180309160427) do add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree create_table "internal_ids", id: :bigserial, force: :cascade do |t| - t.integer "project_id" + t.integer "project_id", null: false t.integer "usage", null: false t.integer "last_value", null: false end @@ -2066,7 +2066,7 @@ ActiveRecord::Schema.define(version: 20180309160427) do add_foreign_key "gpg_signatures", "gpg_keys", on_delete: :nullify add_foreign_key "gpg_signatures", "projects", on_delete: :cascade add_foreign_key "group_custom_attributes", "namespaces", column: "group_id", on_delete: :cascade - add_foreign_key "internal_ids", "projects", name: "fk_f7d46b66c6", on_delete: :cascade + add_foreign_key "internal_ids", "projects", on_delete: :cascade add_foreign_key "issue_assignees", "issues", name: "fk_b7d881734a", on_delete: :cascade add_foreign_key "issue_assignees", "users", name: "fk_5e0c8d9154", on_delete: :cascade add_foreign_key "issue_metrics", "issues", on_delete: :cascade |