chore(schema): add attestation_templates#state
This commit is contained in:
parent
d7f953f08c
commit
ad3c5a7493
4 changed files with 26 additions and 1 deletions
|
@ -7,6 +7,11 @@ class AttestationTemplate < ApplicationRecord
|
||||||
has_one_attached :logo
|
has_one_attached :logo
|
||||||
has_one_attached :signature
|
has_one_attached :signature
|
||||||
|
|
||||||
|
enum state: {
|
||||||
|
draft: 'draft',
|
||||||
|
published: 'published'
|
||||||
|
}
|
||||||
|
|
||||||
validates :title, tags: true, if: -> { procedure.present? && version == 1 }
|
validates :title, tags: true, if: -> { procedure.present? && version == 1 }
|
||||||
validates :body, tags: true, if: -> { procedure.present? && version == 1 }
|
validates :body, tags: true, if: -> { procedure.present? && version == 1 }
|
||||||
validates :json_body, tags: true, if: -> { procedure.present? && version == 2 }
|
validates :json_body, tags: true, if: -> { procedure.present? && version == 2 }
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddStateToAttestationTemplates < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :attestation_templates, :state, :string, default: 'published'
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
class AddAttestationTemplateUnicityIndex < ActiveRecord::Migration[7.0]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def change
|
||||||
|
# this index was not created on production
|
||||||
|
if index_exists?(:attestation_templates, [:procedure_id, :version])
|
||||||
|
remove_index :attestation_templates, [:procedure_id, :version], unique: true, algorithm: :concurrently
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :attestation_templates, [:procedure_id, :version, :state], name: "index_attestation_templates_on_procedure_version_state", unique: true, algorithm: :concurrently
|
||||||
|
end
|
||||||
|
end
|
|
@ -175,10 +175,11 @@ ActiveRecord::Schema[7.0].define(version: 2024_05_27_090508) do
|
||||||
t.string "label_logo"
|
t.string "label_logo"
|
||||||
t.boolean "official_layout", default: true, null: false
|
t.boolean "official_layout", default: true, null: false
|
||||||
t.integer "procedure_id"
|
t.integer "procedure_id"
|
||||||
|
t.string "state", default: "published"
|
||||||
t.text "title"
|
t.text "title"
|
||||||
t.datetime "updated_at", precision: nil, null: false
|
t.datetime "updated_at", precision: nil, null: false
|
||||||
t.integer "version", default: 1, null: false
|
t.integer "version", default: 1, null: false
|
||||||
t.index ["procedure_id", "version"], name: "index_attestation_templates_on_procedure_id_and_version", unique: true
|
t.index ["procedure_id", "version", "state"], name: "index_attestation_templates_on_procedure_version_state", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "attestations", id: :serial, force: :cascade do |t|
|
create_table "attestations", id: :serial, force: :cascade do |t|
|
||||||
|
|
Loading…
Reference in a new issue