chore(schema): add dossiers_count & instructeur_id to exports

This commit is contained in:
Colin Darie 2023-10-09 09:15:54 +02:00
parent 585b5673e1
commit 760005de35
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
4 changed files with 19 additions and 1 deletions

View file

@ -29,6 +29,7 @@ class Export < ApplicationRecord
has_and_belongs_to_many :groupe_instructeurs
belongs_to :procedure_presentation, optional: true
belongs_to :instructeur, optional: true
has_one_attached :file

View file

@ -0,0 +1,11 @@
class AddContextToExports < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
safety_assured do
add_reference :exports, :instructeur, foreign_key: true, null: true, default: nil, index: { algorithm: :concurrently }
end
add_column :exports, :dossiers_count, :integer, null: true, default: nil
end
end

View file

@ -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_09_28_083809) do
ActiveRecord::Schema[7.0].define(version: 2023_10_09_070354) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@ -533,7 +533,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do
create_table "exports", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false
t.integer "dossiers_count"
t.string "format", null: false
t.bigint "instructeur_id"
t.string "job_status", default: "pending", null: false
t.text "key", null: false
t.bigint "procedure_presentation_id"
@ -541,6 +543,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do
t.string "statut", default: "tous"
t.string "time_span_type", default: "everything", null: false
t.datetime "updated_at", precision: 6, null: false
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"
end
@ -1102,6 +1105,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_28_083809) do
add_foreign_key "experts", "users"
add_foreign_key "experts_procedures", "experts"
add_foreign_key "experts_procedures", "procedures"
add_foreign_key "exports", "instructeurs"
add_foreign_key "france_connect_informations", "users"
add_foreign_key "geo_areas", "champs"
add_foreign_key "groupe_instructeurs", "procedures"

View file

@ -7,6 +7,8 @@ FactoryBot.define do
after(:build) do |export, _evaluator|
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), export.procedure_presentation)
export.instructeur = export.groupe_instructeurs.first&.instructeurs&.first
export.dossiers_count = 10 if !export.pending?
end
end
end