From 5f5714678cecf3a441d41c383599b9b995ba4667 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 30 Jun 2023 11:26:23 +0200 Subject: [PATCH] feat(DossierAsignment): create model --- .rubocop.yml | 1 + app/models/dossier.rb | 2 ++ app/models/dossier_assignment.rb | 22 +++++++++++++++++++ ...230630091637_create_dossier_assignments.rb | 14 ++++++++++++ db/schema.rb | 15 ++++++++++++- 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/models/dossier_assignment.rb create mode 100644 db/migrate/20230630091637_create_dossier_assignments.rb diff --git a/.rubocop.yml b/.rubocop.yml index 9b9a9089a..996908ae9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -743,6 +743,7 @@ Rails/CreateTableWithTimestamps: - db/migrate/2017*.rb - db/migrate/2018*.rb - db/migrate/20200630140356_create_traitements.rb + - db/migrate/20230630091637_create_dossier_assignments.rb Rails/Date: Enabled: false diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 1ea1efb3e..be164a13b 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -155,6 +155,8 @@ class Dossier < ApplicationRecord has_one :traitement, -> { order(processed_at: :desc) }, inverse_of: false has_many :dossier_operation_logs, -> { order(:created_at) }, inverse_of: :dossier + has_many :dossier_assignments, -> { order(:assigned_at) }, inverse_of: :dossier, dependent: :destroy + has_one :dossier_assignment, -> { order(assigned_at: :desc) }, inverse_of: false belongs_to :groupe_instructeur, optional: true belongs_to :revision, class_name: 'ProcedureRevision', optional: false diff --git a/app/models/dossier_assignment.rb b/app/models/dossier_assignment.rb new file mode 100644 index 000000000..bd100b599 --- /dev/null +++ b/app/models/dossier_assignment.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: dossier_assignments +# +# id :bigint not null, primary key +# assigned_at :datetime not null +# assigned_by :string +# groupe_instructeur_label :string +# mode :string not null +# previous_groupe_instructeur_label :string +# dossier_id :bigint not null +# groupe_instructeur_id :bigint +# previous_groupe_instructeur_id :bigint +# +class DossierAssignment < ApplicationRecord + belongs_to :dossier + + enum mode: { + auto: 'auto', + manual: 'manual' + } +end diff --git a/db/migrate/20230630091637_create_dossier_assignments.rb b/db/migrate/20230630091637_create_dossier_assignments.rb new file mode 100644 index 000000000..6dc77f03f --- /dev/null +++ b/db/migrate/20230630091637_create_dossier_assignments.rb @@ -0,0 +1,14 @@ +class CreateDossierAssignments < ActiveRecord::Migration[7.0] + def change + create_table :dossier_assignments do |t| + t.references :dossier, foreign_key: true, null: false + t.string :mode, null: false + t.bigint :groupe_instructeur_id + t.bigint :previous_groupe_instructeur_id + t.string :groupe_instructeur_label + t.string :previous_groupe_instructeur_label + t.string :assigned_by + t.timestamp :assigned_at, null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c50569b18..cd6e7611a 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[7.0].define(version: 2023_07_18_113720) do +ActiveRecord::Schema[7.0].define(version: 2023_07_18_113820) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -307,6 +307,18 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_18_113720) do t.index ["procedure_id"], name: "index_deleted_dossiers_on_procedure_id" end + create_table "dossier_assignments", force: :cascade do |t| + t.datetime "assigned_at", precision: nil, null: false + t.string "assigned_by" + t.bigint "dossier_id", null: false + t.bigint "groupe_instructeur_id" + t.string "groupe_instructeur_label" + t.string "mode", null: false + t.bigint "previous_groupe_instructeur_id" + t.string "previous_groupe_instructeur_label" + t.index ["dossier_id"], name: "index_dossier_assignments_on_dossier_id" + end + create_table "dossier_batch_operations", force: :cascade do |t| t.bigint "batch_operation_id", null: false t.datetime "created_at", precision: 6, null: false @@ -1030,6 +1042,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_18_113720) do add_foreign_key "commentaires", "dossiers" add_foreign_key "commentaires", "experts" add_foreign_key "commentaires", "instructeurs" + add_foreign_key "dossier_assignments", "dossiers" add_foreign_key "dossier_batch_operations", "batch_operations" add_foreign_key "dossier_batch_operations", "dossiers" add_foreign_key "dossier_corrections", "commentaires"