Revert "Merge pull request #7637 from tchak/chore-add-missing-foreign-keys"

This reverts commit b21ee46dc2, reversing
changes made to dd85b5c35c.
This commit is contained in:
Paul Chavard 2022-09-21 15:20:42 +02:00
parent 673ea9843e
commit 16bba911ba
43 changed files with 75 additions and 123 deletions

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champ < ApplicationRecord
belongs_to :dossier, inverse_of: false, touch: true, optional: false

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::AddressChamp < Champs::TextChamp
def full_address?

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::AnnuaireEducationChamp < Champs::TextChamp
def fetch_external_data?

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::CarteChamp < Champ
# Default map location. Center of the World, ahm, France...

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::CheckboxChamp < Champs::YesNoChamp
def true?

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::CiviliteChamp < Champ
def html_label?

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::CnafChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/cnaf-input-validation.middleware.ts

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::CommuneChamp < Champs::TextChamp
store_accessor :value_json, :departement, :code_departement

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DateChamp < Champ
before_save :format_before_save

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DatetimeChamp < Champ
before_save :format_before_save

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DecimalNumberChamp < Champ
validates :value, numericality: {

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DepartementChamp < Champs::TextChamp
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DgfipChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/dgfip-input-validation.middleware.ts

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DossierLinkChamp < Champ
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::DropDownListChamp < Champ
THRESHOLD_NB_OPTIONS_AS_RADIO = 5

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::EmailChamp < Champs::TextChamp
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::EngagementChamp < Champs::CheckboxChamp
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::ExplicationChamp < Champs::TextChamp
def search_terms

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::HeaderSectionChamp < Champ
def search_terms

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::IbanChamp < Champ
validates_with IbanValidator

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::IntegerNumberChamp < Champ
validates :value, numericality: {

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::LinkedDropDownListChamp < Champ
delegate :primary_options, :secondary_options, to: 'type_de_champ.dynamic_type'

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::MesriChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/mesri-input-validation.middleware.ts

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::MultipleDropDownListChamp < Champ
before_save :format_before_save

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::NumberChamp < Champ
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::PaysChamp < Champs::TextChamp
def localized_value

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::PhoneChamp < Champs::TextChamp
# We want to allow:

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::PieceJustificativeChamp < Champ
FILE_MAX_SIZE = 200.megabytes

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::PoleEmploiChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/pole-emploi-input-validation.middleware.ts

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::RegionChamp < Champs::TextChamp
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::RepetitionChamp < Champ
accepts_nested_attributes_for :champs, allow_destroy: true

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::SiretChamp < Champ
def search_terms

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::TextChamp < Champ
end

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::TextareaChamp < Champs::TextChamp
def for_export

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::TitreIdentiteChamp < Champ
FILE_MAX_SIZE = 20.megabytes

View file

@ -13,11 +13,11 @@
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
# type_de_champ_id :integer
#
class Champs::YesNoChamp < Champ
def search_terms

View file

@ -1,11 +0,0 @@
class AddMissingForeignKeys < ActiveRecord::Migration[6.1]
def change
add_foreign_key :champs, :dossiers, validate: false
add_foreign_key :champs, :types_de_champ, validate: false
add_foreign_key :champs, :etablissements, validate: false
add_foreign_key :etablissements, :dossiers, validate: false
add_check_constraint :champs, "dossier_id IS NOT NULL", name: "champs_dossier_id_null", validate: false
add_check_constraint :champs, "type_de_champ_id IS NOT NULL", name: "champs_type_de_champ_id_null", validate: false
end
end

View file

@ -1,8 +0,0 @@
class ValidateMissingForeignKeys < ActiveRecord::Migration[6.1]
def change
validate_foreign_key :champs, :dossiers
validate_foreign_key :champs, :types_de_champ
validate_foreign_key :champs, :etablissements
validate_foreign_key :etablissements, :dossiers
end
end

View file

@ -1,7 +0,0 @@
class ValidateNotNullChampsTypeDeChampId < ActiveRecord::Migration[6.1]
def change
validate_check_constraint :champs, name: "champs_type_de_champ_id_null"
change_column_null :champs, :type_de_champ_id, false
remove_check_constraint :champs, name: "champs_type_de_champ_id_null"
end
end

View file

@ -1,7 +0,0 @@
class ValidateNotNullChampsDossierId < ActiveRecord::Migration[6.1]
def change
validate_check_constraint :champs, name: "champs_dossier_id_null"
change_column_null :champs, :dossier_id, false
remove_check_constraint :champs, name: "champs_dossier_id_null"
end
end

View file

@ -1,5 +0,0 @@
class AddForeignKeyToAttachmentsBlobId < ActiveRecord::Migration[6.1]
def change
add_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id, validate: false
end
end

View file

@ -1,5 +0,0 @@
class ValidateForeignKeyOnAttachmentsBlobId < ActiveRecord::Migration[6.1]
def change
validate_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_09_04_151920) do
ActiveRecord::Schema.define(version: 2022_09_02_151920) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
@ -185,7 +185,7 @@ ActiveRecord::Schema.define(version: 2022_09_04_151920) do
create_table "champs", id: :serial, force: :cascade do |t|
t.datetime "created_at"
t.jsonb "data"
t.integer "dossier_id", null: false
t.integer "dossier_id"
t.integer "etablissement_id"
t.string "external_id"
t.string "fetch_external_data_exceptions", array: true
@ -194,7 +194,7 @@ ActiveRecord::Schema.define(version: 2022_09_04_151920) do
t.datetime "rebased_at"
t.integer "row"
t.string "type"
t.integer "type_de_champ_id", null: false
t.integer "type_de_champ_id"
t.datetime "updated_at"
t.string "value"
t.jsonb "value_json"
@ -869,7 +869,6 @@ ActiveRecord::Schema.define(version: 2022_09_04_151920) do
t.index ["acronym"], name: "index_zones_on_acronym", unique: true
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "administrateurs", "users"
add_foreign_key "administrateurs_instructeurs", "administrateurs"
@ -886,9 +885,6 @@ ActiveRecord::Schema.define(version: 2022_09_04_151920) do
add_foreign_key "bulk_messages_groupe_instructeurs", "bulk_messages"
add_foreign_key "bulk_messages_groupe_instructeurs", "groupe_instructeurs"
add_foreign_key "champs", "champs", column: "parent_id"
add_foreign_key "champs", "dossiers"
add_foreign_key "champs", "etablissements"
add_foreign_key "champs", "types_de_champ"
add_foreign_key "closed_mails", "procedures"
add_foreign_key "commentaires", "dossiers"
add_foreign_key "commentaires", "experts"
@ -898,7 +894,6 @@ ActiveRecord::Schema.define(version: 2022_09_04_151920) do
add_foreign_key "dossiers", "groupe_instructeurs"
add_foreign_key "dossiers", "procedure_revisions", column: "revision_id"
add_foreign_key "dossiers", "users"
add_foreign_key "etablissements", "dossiers"
add_foreign_key "experts", "users"
add_foreign_key "experts_procedures", "experts"
add_foreign_key "experts_procedures", "procedures"