From 35461f01593183d33153f57acac83513b7bc4edb Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 21 Jul 2020 10:39:57 +0200 Subject: [PATCH] Add revisions migrations --- config/initializers/inflections.rb | 3 ++ ...200707082260_create_procedure_revisions.rb | 24 +++++++++++++ ...reate_procedure_revision_types_de_champ.rb | 14 ++++++++ db/schema.rb | 34 ++++++++++++++++++- 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200707082260_create_procedure_revisions.rb create mode 100644 db/migrate/20200707082261_create_procedure_revision_types_de_champ.rb diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index d2e9e63da..69ce9269b 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -12,6 +12,9 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'RNA' inflect.irregular 'type_de_champ', 'types_de_champ' inflect.irregular 'type_de_champ_private', 'types_de_champ_private' + inflect.irregular 'procedure_revision_type_de_champ', 'procedure_revision_types_de_champ' + inflect.irregular 'revision_type_de_champ', 'revision_types_de_champ' + inflect.irregular 'revision_type_de_champ_private', 'revision_types_de_champ_private' inflect.irregular 'assign_to', 'assign_tos' inflect.uncountable(['avis', 'pays']) end diff --git a/db/migrate/20200707082260_create_procedure_revisions.rb b/db/migrate/20200707082260_create_procedure_revisions.rb new file mode 100644 index 000000000..ee56f1609 --- /dev/null +++ b/db/migrate/20200707082260_create_procedure_revisions.rb @@ -0,0 +1,24 @@ +class CreateProcedureRevisions < ActiveRecord::Migration[5.2] + def change + create_table :procedure_revisions do |t| + t.references :procedure, foreign_key: true, null: false, index: true + + t.timestamps + end + + add_column :dossiers, :revision_id, :bigint + add_column :types_de_champ, :revision_id, :bigint + add_column :procedures, :draft_revision_id, :bigint + add_column :procedures, :published_revision_id, :bigint + + add_foreign_key :dossiers, :procedure_revisions, column: :revision_id + add_foreign_key :types_de_champ, :procedure_revisions, column: :revision_id + add_foreign_key :procedures, :procedure_revisions, column: :draft_revision_id + add_foreign_key :procedures, :procedure_revisions, column: :published_revision_id + + add_index :dossiers, :revision_id + add_index :types_de_champ, :revision_id + add_index :procedures, :draft_revision_id + add_index :procedures, :published_revision_id + end +end diff --git a/db/migrate/20200707082261_create_procedure_revision_types_de_champ.rb b/db/migrate/20200707082261_create_procedure_revision_types_de_champ.rb new file mode 100644 index 000000000..2f65df6d3 --- /dev/null +++ b/db/migrate/20200707082261_create_procedure_revision_types_de_champ.rb @@ -0,0 +1,14 @@ +class CreateProcedureRevisionTypesDeChamp < ActiveRecord::Migration[5.2] + def change + create_table :procedure_revision_types_de_champ do |t| + t.references :revision, null: false, index: true + t.references :type_de_champ, foreign_key: true, null: false, index: true + + t.integer :position, null: false + + t.timestamps + end + + add_foreign_key :procedure_revision_types_de_champ, :procedure_revisions, column: :revision_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 8954f1d5e..3c242925f 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_07_15_143010) do +ActiveRecord::Schema.define(version: 2020_07_16_143010) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -259,9 +259,11 @@ ActiveRecord::Schema.define(version: 2020_07_15_143010) do t.datetime "termine_close_to_expiration_notice_sent_at" t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin + t.bigint "revision_id" t.index ["archived"], name: "index_dossiers_on_archived" t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id" t.index ["hidden_at"], name: "index_dossiers_on_hidden_at" + t.index ["revision_id"], name: "index_dossiers_on_revision_id" t.index ["state"], name: "index_dossiers_on_state" t.index ["user_id"], name: "index_dossiers_on_user_id" end @@ -476,6 +478,23 @@ ActiveRecord::Schema.define(version: 2020_07_15_143010) do t.index ["assign_to_id"], name: "index_procedure_presentations_on_assign_to_id", unique: true end + create_table "procedure_revision_types_de_champ", force: :cascade do |t| + t.bigint "revision_id", null: false + t.bigint "type_de_champ_id", null: false + t.integer "position", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["revision_id"], name: "index_procedure_revision_types_de_champ_on_revision_id" + t.index ["type_de_champ_id"], name: "index_procedure_revision_types_de_champ_on_type_de_champ_id" + end + + create_table "procedure_revisions", force: :cascade do |t| + t.bigint "procedure_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["procedure_id"], name: "index_procedure_revisions_on_procedure_id" + end + create_table "procedures", id: :serial, force: :cascade do |t| t.string "libelle" t.string "description" @@ -517,10 +536,14 @@ ActiveRecord::Schema.define(version: 2020_07_15_143010) do t.datetime "unpublished_at" t.bigint "canonical_procedure_id" t.string "api_entreprise_token" + t.bigint "draft_revision_id" + t.bigint "published_revision_id" t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state" + t.index ["draft_revision_id"], name: "index_procedures_on_draft_revision_id" t.index ["hidden_at"], name: "index_procedures_on_hidden_at" t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id" t.index ["path", "closed_at", "hidden_at"], name: "index_procedures_on_path_and_closed_at_and_hidden_at", unique: true + t.index ["published_revision_id"], name: "index_procedures_on_published_revision_id" t.index ["service_id"], name: "index_procedures_on_service_id" end @@ -592,9 +615,11 @@ ActiveRecord::Schema.define(version: 2020_07_15_143010) do t.jsonb "options" t.bigint "stable_id" t.bigint "parent_id" + t.bigint "revision_id" t.index ["parent_id"], name: "index_types_de_champ_on_parent_id" t.index ["private"], name: "index_types_de_champ_on_private" t.index ["procedure_id"], name: "index_types_de_champ_on_procedure_id" + t.index ["revision_id"], name: "index_types_de_champ_on_revision_id" t.index ["stable_id"], name: "index_types_de_champ_on_stable_id" end @@ -660,18 +685,25 @@ ActiveRecord::Schema.define(version: 2020_07_15_143010) do add_foreign_key "dossier_operation_logs", "dossiers" add_foreign_key "dossier_operation_logs", "instructeurs" add_foreign_key "dossiers", "groupe_instructeurs" + add_foreign_key "dossiers", "procedure_revisions", column: "revision_id" add_foreign_key "dossiers", "users" add_foreign_key "feedbacks", "users" add_foreign_key "geo_areas", "champs" add_foreign_key "groupe_instructeurs", "procedures" add_foreign_key "initiated_mails", "procedures" add_foreign_key "procedure_presentations", "assign_tos" + add_foreign_key "procedure_revision_types_de_champ", "procedure_revisions", column: "revision_id" + add_foreign_key "procedure_revision_types_de_champ", "types_de_champ" + add_foreign_key "procedure_revisions", "procedures" + add_foreign_key "procedures", "procedure_revisions", column: "draft_revision_id" + add_foreign_key "procedures", "procedure_revisions", column: "published_revision_id" add_foreign_key "procedures", "services" add_foreign_key "received_mails", "procedures" add_foreign_key "refused_mails", "procedures" add_foreign_key "services", "administrateurs" add_foreign_key "traitements", "dossiers" add_foreign_key "trusted_device_tokens", "instructeurs" + add_foreign_key "types_de_champ", "procedure_revisions", column: "revision_id" add_foreign_key "types_de_champ", "types_de_champ", column: "parent_id" add_foreign_key "users", "administrateurs" add_foreign_key "users", "instructeurs"