From 9243ae69dfdd7ed2fd1c1c552fb11c17167b514d Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 19 Mar 2020 11:51:47 +0100 Subject: [PATCH] Add reason to DeletedDossier # Conflicts: # db/schema.rb --- app/models/deleted_dossier.rb | 17 +++++++++++++++-- ...0319103836_add_reason_to_deleted_dossiers.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200319103836_add_reason_to_deleted_dossiers.rb diff --git a/app/models/deleted_dossier.rb b/app/models/deleted_dossier.rb index 25338f6b4..bce5518ee 100644 --- a/app/models/deleted_dossier.rb +++ b/app/models/deleted_dossier.rb @@ -1,7 +1,20 @@ class DeletedDossier < ApplicationRecord belongs_to :procedure - def self.create_from_dossier(dossier) - DeletedDossier.create!(dossier_id: dossier.id, procedure: dossier.procedure, state: dossier.state, deleted_at: Time.zone.now) + enum reason: { + user_request: 'user_request', + manager_request: 'manager_request', + user_removed: 'user_removed', + expired: 'expired' + } + + def self.create_from_dossier(dossier, reason) + create!( + reason: reasons.fetch(reason), + dossier_id: dossier.id, + procedure: dossier.procedure, + state: dossier.state, + deleted_at: Time.zone.now + ) end end diff --git a/db/migrate/20200319103836_add_reason_to_deleted_dossiers.rb b/db/migrate/20200319103836_add_reason_to_deleted_dossiers.rb new file mode 100644 index 000000000..4b882b537 --- /dev/null +++ b/db/migrate/20200319103836_add_reason_to_deleted_dossiers.rb @@ -0,0 +1,5 @@ +class AddReasonToDeletedDossiers < ActiveRecord::Migration[5.2] + def change + add_column :deleted_dossiers, :reason, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index a7a596376..c6ed4c550 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: 2020_03_04_155418) do +ActiveRecord::Schema.define(version: 2020_03_19_103836) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -213,6 +213,7 @@ ActiveRecord::Schema.define(version: 2020_03_04_155418) do t.string "state" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "reason" t.index ["procedure_id"], name: "index_deleted_dossiers_on_procedure_id" end