about summary refs log tree commit diff
path: root/db/migrate/20220611212541_add_role_id_to_users.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20220611212541_add_role_id_to_users.rb')
-rw-r--r--db/migrate/20220611212541_add_role_id_to_users.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/db/migrate/20220611212541_add_role_id_to_users.rb b/db/migrate/20220611212541_add_role_id_to_users.rb
new file mode 100644
index 000000000..2fda647d4
--- /dev/null
+++ b/db/migrate/20220611212541_add_role_id_to_users.rb
@@ -0,0 +1,8 @@
+class AddRoleIdToUsers < ActiveRecord::Migration[6.1]
+  disable_ddl_transaction!
+
+  def change
+    safety_assured { add_reference :users, :role, foreign_key: { to_table: 'user_roles', on_delete: :nullify }, index: false }
+    add_index :users, :role_id, algorithm: :concurrently, where: 'role_id IS NOT NULL'
+  end
+end