From 7661b8b1b2859a77296ba64016f5ff57a0f0ace5 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 8 Mar 2024 10:11:11 +0100 Subject: [PATCH] add export_template to exports --- app/models/export.rb | 1 + db/migrate/20240131094915_add_template_to_exports.rb | 6 ++++++ db/migrate/20240131095645_add_export_template_fk.rb | 5 +++++ db/migrate/20240131100329_validate_export_template_fk.rb | 5 +++++ db/schema.rb | 3 +++ 5 files changed, 20 insertions(+) create mode 100644 db/migrate/20240131094915_add_template_to_exports.rb create mode 100644 db/migrate/20240131095645_add_export_template_fk.rb create mode 100644 db/migrate/20240131100329_validate_export_template_fk.rb diff --git a/app/models/export.rb b/app/models/export.rb index 3a7a1ac34..66832d5e1 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -31,6 +31,7 @@ class Export < ApplicationRecord belongs_to :procedure_presentation, optional: true belongs_to :instructeur, optional: true belongs_to :user_profile, polymorphic: true, optional: true + belongs_to :export_template, optional: true has_one_attached :file diff --git a/db/migrate/20240131094915_add_template_to_exports.rb b/db/migrate/20240131094915_add_template_to_exports.rb new file mode 100644 index 000000000..397f053b7 --- /dev/null +++ b/db/migrate/20240131094915_add_template_to_exports.rb @@ -0,0 +1,6 @@ +class AddTemplateToExports < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + def change + add_reference :exports, :export_template, null: true, index: { algorithm: :concurrently } + end +end diff --git a/db/migrate/20240131095645_add_export_template_fk.rb b/db/migrate/20240131095645_add_export_template_fk.rb new file mode 100644 index 000000000..3e90045bc --- /dev/null +++ b/db/migrate/20240131095645_add_export_template_fk.rb @@ -0,0 +1,5 @@ +class AddExportTemplateFk < ActiveRecord::Migration[7.0] + def change + add_foreign_key :exports, :export_templates, validate: false + end +end diff --git a/db/migrate/20240131100329_validate_export_template_fk.rb b/db/migrate/20240131100329_validate_export_template_fk.rb new file mode 100644 index 000000000..08180880d --- /dev/null +++ b/db/migrate/20240131100329_validate_export_template_fk.rb @@ -0,0 +1,5 @@ +class ValidateExportTemplateFk < ActiveRecord::Migration[7.0] + def change + validate_foreign_key :exports, :export_templates + end +end diff --git a/db/schema.rb b/db/schema.rb index 054c32caa..22ee0febd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -606,6 +606,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_04_17_053843) do create_table "exports", force: :cascade do |t| t.datetime "created_at", precision: nil, null: false t.integer "dossiers_count" + t.bigint "export_template_id" t.string "format", null: false t.bigint "instructeur_id" t.string "job_status", default: "pending", null: false @@ -617,6 +618,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_04_17_053843) do t.datetime "updated_at", precision: nil, null: false t.bigint "user_profile_id" t.string "user_profile_type" + t.index ["export_template_id"], name: "index_exports_on_export_template_id" t.index ["instructeur_id"], name: "index_exports_on_instructeur_id" t.index ["key"], name: "index_exports_on_key" t.index ["procedure_presentation_id"], name: "index_exports_on_procedure_presentation_id" @@ -1235,6 +1237,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_04_17_053843) do add_foreign_key "experts_procedures", "experts" add_foreign_key "experts_procedures", "procedures" add_foreign_key "export_templates", "groupe_instructeurs" + add_foreign_key "exports", "export_templates" add_foreign_key "exports", "instructeurs" add_foreign_key "france_connect_informations", "users" add_foreign_key "geo_areas", "champs"