feat(exports): add statut and procedure_presentation to exports

This commit is contained in:
Paul Chavard 2022-04-05 15:53:15 +02:00
parent 19d07a01d5
commit be1a2f916d
5 changed files with 39 additions and 10 deletions

View file

@ -2,12 +2,14 @@
# #
# Table name: exports # Table name: exports
# #
# id :bigint not null, primary key # id :bigint not null, primary key
# format :string not null # format :string not null
# key :text not null # key :text not null
# time_span_type :string default("everything"), not null # statut :string default("tous")
# created_at :datetime not null # time_span_type :string default("everything"), not null
# updated_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null
# procedure_presentation_id :bigint
# #
class Export < ApplicationRecord class Export < ApplicationRecord
MAX_DUREE_CONSERVATION_EXPORT = 3.hours MAX_DUREE_CONSERVATION_EXPORT = 3.hours
@ -23,7 +25,18 @@ class Export < ApplicationRecord
monthly: 'monthly' monthly: 'monthly'
} }
enum statut: {
'a-suivre': 'a-suivre',
suivis: 'suivis',
traites: 'traites',
tous: 'tous',
supprimes_recemment: 'supprimes_recemment',
archives: 'archives',
expirant: 'expirant'
}
has_and_belongs_to_many :groupe_instructeurs has_and_belongs_to_many :groupe_instructeurs
belongs_to :procedure_presentation, optional: true
has_one_attached :file has_one_attached :file

View file

@ -25,6 +25,8 @@ class ProcedurePresentation < ApplicationRecord
FILTERS_VALUE_MAX_LENGTH = 100 FILTERS_VALUE_MAX_LENGTH = 100
belongs_to :assign_to, optional: false belongs_to :assign_to, optional: false
has_many :exports, dependent: :destroy
delegate :procedure, :instructeur, to: :assign_to delegate :procedure, :instructeur, to: :assign_to
validate :check_allowed_displayed_fields validate :check_allowed_displayed_fields

View file

@ -0,0 +1,10 @@
class AddProcedurePresentationAndStateToExports < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_reference :exports, :procedure_presentation, null: true, index: { algorithm: :concurrently }
add_column :exports, :statut, :string, default: 'tous'
remove_index :exports, [:format, :time_span_type, :key]
add_index :exports, [:format, :time_span_type, :statut, :key], unique: true, algorithm: :concurrently
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_04_05_100354) do ActiveRecord::Schema.define(version: 2022_04_05_110354) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -431,9 +431,12 @@ ActiveRecord::Schema.define(version: 2022_04_05_100354) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.string "format", null: false t.string "format", null: false
t.text "key", null: false t.text "key", null: false
t.bigint "procedure_presentation_id"
t.string "statut", default: "tous"
t.string "time_span_type", default: "everything", null: false t.string "time_span_type", default: "everything", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["format", "time_span_type", "key"], name: "index_exports_on_format_and_time_span_type_and_key", unique: true t.index ["format", "time_span_type", "statut", "key"], name: "index_exports_on_format_and_time_span_type_and_statut_and_key", unique: true
t.index ["procedure_presentation_id"], name: "index_exports_on_procedure_presentation_id"
end end
create_table "exports_groupe_instructeurs", force: :cascade do |t| create_table "exports_groupe_instructeurs", force: :cascade do |t|

View file

@ -1,11 +1,12 @@
FactoryBot.define do FactoryBot.define do
factory :export do factory :export do
format { :csv } format { Export.formats.fetch(:csv) }
statut { Export.statuts.fetch(:tous) }
time_span_type { Export.time_span_types.fetch(:everything) } time_span_type { Export.time_span_types.fetch(:everything) }
groupe_instructeurs { [association(:groupe_instructeur)] } groupe_instructeurs { [association(:groupe_instructeur)] }
after(:build) do |export, _evaluator| after(:build) do |export, _evaluator|
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id)) export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), export.procedure_presentation&.id)
end end
end end
end end