From f30dadfb533f6543f0c6f4be17ab909868d5b376 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 27 Jun 2018 11:23:31 +0200 Subject: [PATCH] Update search to version 4 --- ...0627092237_update_searches_to_version_4.rb | 9 +++++ db/schema.rb | 7 ++-- db/views/searches_v04.sql | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20180627092237_update_searches_to_version_4.rb create mode 100644 db/views/searches_v04.sql diff --git a/db/migrate/20180627092237_update_searches_to_version_4.rb b/db/migrate/20180627092237_update_searches_to_version_4.rb new file mode 100644 index 000000000..92bc9a8b7 --- /dev/null +++ b/db/migrate/20180627092237_update_searches_to_version_4.rb @@ -0,0 +1,9 @@ +class UpdateSearchesToVersion4 < ActiveRecord::Migration[5.2] + def up + replace_view :searches, version: 4 + end + + def down + replace_view :searches, version: 3 + end +end diff --git a/db/schema.rb b/db/schema.rb index 1a351cd1d..0dc4b2cc9 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: 2018_06_01_084546) do +ActiveRecord::Schema.define(version: 2018_06_27_092237) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -632,11 +632,10 @@ ActiveRecord::Schema.define(version: 2018_06_01_084546) do create_view "searches", sql_definition: <<-SQL SELECT dossiers.id AS dossier_id, - (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_siren, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_nom, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_prenom, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.association_rna, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.association_titre, ''::character varying))::text) || ' '::text) || COALESCE(etablissements.association_objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term - FROM ((((((((dossiers + (((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_siren, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_nom, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.entreprise_prenom, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.association_rna, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.association_titre, ''::character varying))::text) || ' '::text) || COALESCE(etablissements.association_objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term + FROM (((((((dossiers JOIN users ON ((users.id = dossiers.user_id))) LEFT JOIN france_connect_informations ON ((france_connect_informations.user_id = dossiers.user_id))) - LEFT JOIN cerfas ON ((cerfas.dossier_id = dossiers.id))) LEFT JOIN champs ON ((champs.dossier_id = dossiers.id))) LEFT JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) LEFT JOIN etablissements ON ((etablissements.dossier_id = dossiers.id))) diff --git a/db/views/searches_v04.sql b/db/views/searches_v04.sql new file mode 100644 index 000000000..f628d2f20 --- /dev/null +++ b/db/views/searches_v04.sql @@ -0,0 +1,39 @@ +-- this version merges all possible search terms together, complicating the +-- view, but enables searching for multiple terms from multiple tables at once. + +SELECT dossiers.id AS dossier_id, + COALESCE(users.email, '') || ' ' || + COALESCE(france_connect_informations.given_name, '') || ' ' || + COALESCE(france_connect_informations.family_name, '') || ' ' || + COALESCE(champs.value, '') || ' ' || + COALESCE(drop_down_lists.value, '') || ' ' || + COALESCE(etablissements.entreprise_siren, '') || ' ' || + COALESCE(etablissements.entreprise_numero_tva_intracommunautaire, '') || ' ' || + COALESCE(etablissements.entreprise_forme_juridique, '') || ' ' || + COALESCE(etablissements.entreprise_forme_juridique_code, '') || ' ' || + COALESCE(etablissements.entreprise_nom_commercial, '') || ' ' || + COALESCE(etablissements.entreprise_raison_sociale, '') || ' ' || + COALESCE(etablissements.entreprise_siret_siege_social, '') || ' ' || + COALESCE(etablissements.entreprise_nom, '') || ' ' || + COALESCE(etablissements.entreprise_prenom, '') || ' ' || + COALESCE(etablissements.association_rna, '') || ' ' || + COALESCE(etablissements.association_titre, '') || ' ' || + COALESCE(etablissements.association_objet, '') || ' ' || + COALESCE(etablissements.siret, '') || ' ' || + COALESCE(etablissements.naf, '') || ' ' || + COALESCE(etablissements.libelle_naf, '') || ' ' || + COALESCE(etablissements.adresse, '') || ' ' || + COALESCE(etablissements.code_postal, '') || ' ' || + COALESCE(etablissements.localite, '') || ' ' || + COALESCE(etablissements.code_insee_localite, '') || ' ' || + COALESCE(individuals.nom, '') || ' ' || + COALESCE(individuals.prenom, '') || ' ' || + COALESCE(pieces_justificatives.content, '') AS term +FROM dossiers +INNER JOIN users ON users.id = dossiers.user_id +LEFT JOIN france_connect_informations ON france_connect_informations.user_id = dossiers.user_id +LEFT JOIN champs ON champs.dossier_id = dossiers.id +LEFT JOIN drop_down_lists ON drop_down_lists.type_de_champ_id = champs.type_de_champ_id +LEFT JOIN etablissements ON etablissements.dossier_id = dossiers.id +LEFT JOIN individuals ON individuals.dossier_id = dossiers.id +LEFT JOIN pieces_justificatives ON pieces_justificatives.dossier_id = dossiers.id