From 561f6fb274f1dcf7f70e63afd1551a36546ef7af Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 1 Dec 2021 21:05:15 +0100 Subject: [PATCH] add belongs_to zone for procedure --- app/models/procedure.rb | 2 ++ db/migrate/20211127143736_add_zone_to_procedures.rb | 5 +++++ db/schema.rb | 5 ++++- spec/factories/procedure.rb | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20211127143736_add_zone_to_procedures.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e85548ce1..eab2c373d 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -48,6 +48,7 @@ # parent_procedure_id :bigint # published_revision_id :bigint # service_id :bigint +# zone_id :bigint # class Procedure < ApplicationRecord @@ -85,6 +86,7 @@ class Procedure < ApplicationRecord belongs_to :parent_procedure, class_name: 'Procedure', optional: true belongs_to :canonical_procedure, class_name: 'Procedure', optional: true belongs_to :service, optional: true + belongs_to :zone, optional: true def active_revision brouillon? ? draft_revision : published_revision diff --git a/db/migrate/20211127143736_add_zone_to_procedures.rb b/db/migrate/20211127143736_add_zone_to_procedures.rb new file mode 100644 index 000000000..4fa95f3f8 --- /dev/null +++ b/db/migrate/20211127143736_add_zone_to_procedures.rb @@ -0,0 +1,5 @@ +class AddZoneToProcedures < ActiveRecord::Migration[6.1] + def change + add_reference :procedures, :zone, null: true, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 6cd7e79c8..6c8fad2c6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_27_133549) do +ActiveRecord::Schema.define(version: 2021_11_27_143736) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -638,6 +638,7 @@ ActiveRecord::Schema.define(version: 2021_11_27_133549) do t.text "api_particulier_scopes", default: [], array: true t.jsonb "api_particulier_sources", default: {} t.boolean "instructeurs_self_management_enabled" + t.bigint "zone_id" t.index ["api_particulier_sources"], name: "index_procedures_on_api_particulier_sources", using: :gin t.boolean "routing_enabled" t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state" @@ -648,6 +649,7 @@ ActiveRecord::Schema.define(version: 2021_11_27_133549) do t.index ["path", "closed_at", "hidden_at"], name: "index_procedures_on_path_and_closed_at_and_hidden_at", unique: true t.index ["published_revision_id"], name: "index_procedures_on_published_revision_id" t.index ["service_id"], name: "index_procedures_on_service_id" + t.index ["zone_id"], name: "index_procedures_on_zone_id" end create_table "received_mails", id: :serial, force: :cascade do |t| @@ -865,6 +867,7 @@ ActiveRecord::Schema.define(version: 2021_11_27_133549) do add_foreign_key "procedures", "procedure_revisions", column: "draft_revision_id" add_foreign_key "procedures", "procedure_revisions", column: "published_revision_id" add_foreign_key "procedures", "services" + add_foreign_key "procedures", "zones" add_foreign_key "received_mails", "procedures" add_foreign_key "refused_mails", "procedures" add_foreign_key "services", "administrateurs" diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 1b6a622d2..8d8cc7fa9 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -12,6 +12,7 @@ FactoryBot.define do ask_birthday { false } lien_site_web { "https://mon-site.gouv" } path { SecureRandom.uuid } + association :zone groupe_instructeurs { [association(:groupe_instructeur, :default, procedure: instance, strategy: :build)] } administrateurs { administrateur.present? ? [administrateur] : [association(:administrateur)] }