db: add foreign keys to Administrateur, Instructeur and Expert

This commit is contained in:
Pierre de La Morinerie 2022-03-08 17:45:36 +01:00
parent be834ba58d
commit 48ea53b90d
5 changed files with 18 additions and 1 deletions

View file

@ -7,6 +7,7 @@
# encrypted_token :string
# created_at :datetime
# updated_at :datetime
# user_id :bigint
#
class Administrateur < ApplicationRecord
include ActiveRecord::SecureToken

View file

@ -5,6 +5,7 @@
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint
#
class Expert < ApplicationRecord
has_one :user

View file

@ -9,6 +9,7 @@
# created_at :datetime
# updated_at :datetime
# agent_connect_id :string
# user_id :bigint
#
class Instructeur < ApplicationRecord
has_and_belongs_to_many :administrateurs

View file

@ -0,0 +1,11 @@
class AddForeignKeysToUserRelatedModels < ActiveRecord::Migration[6.1]
def change
# options = { type: :bigint, index: { unique: true }, foreign_key: true, null: true }
# add_reference :administrateurs, :user, **options
# add_reference :instructeurs, :user, **options
# add_reference :experts, :user, **options
add_column :administrateurs, :user_id, :bigint
add_column :instructeurs, :user_id, :bigint
add_column :experts, :user_id, :bigint
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_03_08_110720) do
ActiveRecord::Schema.define(version: 2022_03_15_113510) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -60,6 +60,7 @@ ActiveRecord::Schema.define(version: 2022_03_08_110720) do
t.datetime "updated_at"
t.boolean "active", default: false
t.string "encrypted_token"
t.bigint "user_id"
end
create_table "administrateurs_instructeurs", id: false, force: :cascade do |t|
@ -411,6 +412,7 @@ ActiveRecord::Schema.define(version: 2022_03_08_110720) do
create_table "experts", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "user_id"
end
create_table "experts_procedures", force: :cascade do |t|
@ -539,6 +541,7 @@ ActiveRecord::Schema.define(version: 2022_03_08_110720) do
t.datetime "login_token_created_at"
t.boolean "bypass_email_login_token", default: false, null: false
t.string "agent_connect_id"
t.bigint "user_id"
t.index ["agent_connect_id"], name: "index_instructeurs_on_agent_connect_id", unique: true
end