summaryrefslogtreecommitdiff
path: root/db/migrate/20200928125258_add_foreign_key_to_u2f_reg_id_in_webauthn_regs.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20200928125258_add_foreign_key_to_u2f_reg_id_in_webauthn_regs.rb')
-rw-r--r--db/migrate/20200928125258_add_foreign_key_to_u2f_reg_id_in_webauthn_regs.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/db/migrate/20200928125258_add_foreign_key_to_u2f_reg_id_in_webauthn_regs.rb b/db/migrate/20200928125258_add_foreign_key_to_u2f_reg_id_in_webauthn_regs.rb
new file mode 100644
index 00000000000..b76b826658e
--- /dev/null
+++ b/db/migrate/20200928125258_add_foreign_key_to_u2f_reg_id_in_webauthn_regs.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class AddForeignKeyToU2fRegIdInWebauthnRegs < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_webauthn_registrations_on_u2f_registration_id'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :webauthn_registrations, :u2f_registration_id, where: 'u2f_registration_id IS NOT NULL', name: INDEX_NAME
+ add_concurrent_foreign_key :webauthn_registrations, :u2f_registrations, column: :u2f_registration_id, on_delete: :cascade
+ end
+
+ def down
+ remove_foreign_key_if_exists :webauthn_registrations, column: :u2f_registration_id
+ remove_concurrent_index_by_name(:webauthn_registrations, INDEX_NAME)
+ end
+end