Merge pull request #1700 from betagouv/prepare-1626

[Ref #1626] Add the administrateurs_procedures table and associations
This commit is contained in:
gregoirenovel 2018-03-23 14:18:18 +01:00 committed by GitHub
commit 197089a746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 1 deletions

View file

@ -7,6 +7,8 @@ class Administrateur < ApplicationRecord
has_and_belongs_to_many :gestionnaires
has_many :procedures
has_many :administrateurs_procedures
has_many :admin_procedures, through: :administrateurs_procedures, source: :procedure
before_validation -> { sanitize_email(:email) }
before_save :ensure_api_token

View file

@ -0,0 +1,4 @@
class AdministrateursProcedure < ApplicationRecord
belongs_to :administrateur
belongs_to :procedure
end

View file

@ -12,6 +12,8 @@ class Procedure < ApplicationRecord
belongs_to :administrateur
has_many :assign_to, dependent: :destroy
has_many :administrateurs_procedures
has_many :administrateurs, through: :administrateurs_procedures
has_many :gestionnaires, through: :assign_to
has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy

View file

@ -0,0 +1,11 @@
class CreateJoinTableAdministrateursProcedures < ActiveRecord::Migration[5.2]
def change
create_join_table :administrateurs, :procedures do |t|
t.timestamps
t.index :administrateur_id
t.index :procedure_id
t.index [:administrateur_id, :procedure_id], unique: true, name: :index_unique_admin_proc_couple
end
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: 2018_03_19_214757) do
ActiveRecord::Schema.define(version: 2018_03_23_101837) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -64,6 +64,16 @@ ActiveRecord::Schema.define(version: 2018_03_19_214757) do
t.index ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id"
end
create_table "administrateurs_procedures", id: false, force: :cascade do |t|
t.bigint "administrateur_id", null: false
t.bigint "procedure_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["administrateur_id", "procedure_id"], name: "index_unique_admin_proc_couple", unique: true
t.index ["administrateur_id"], name: "index_administrateurs_procedures_on_administrateur_id"
t.index ["procedure_id"], name: "index_administrateurs_procedures_on_procedure_id"
end
create_table "administrations", id: :serial, force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false