Skip to content

Commit

Permalink
Update upgrade file to 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pdrillin committed Jun 24, 2021
1 parent 8a60ee9 commit 3824e6c
Showing 1 changed file with 19 additions and 76 deletions.
95 changes: 19 additions & 76 deletions gestion_base_adresse/install/sql/upgrade/upgrade_to_0.8.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ CREATE FUNCTION adresse.lieux_dits()
AS $BODY$
DECLARE
BEGIN
NEW.id_com = (SELECT c.id_com FROM adresse.commune c
WHERE ST_intersects(NEW.geom, c.geom));
NEW.commune_nom = (SELECT c.commune_nom FROM adresse.commune c
WHERE ST_Intersects(NEW.geom, c.geom));
NEW.id_com_del = (SELECT d.id_com_del FROM adresse.commune_deleguee d
WHERE ST_intersects(NEW.geom, d.geom));
NEW.commune_deleguee_nom = (SELECT d.commune_deleguee_nom FROM adresse.commune_deleguee d
WHERE ST_Intersects(NEW.geom, d.geom));
SELECT c.id_com into NEW.id_com, c.commune_nom into NEW.commune_nom
FROM adresse.commune c
WHERE ST_DWithin(NEW.geom, d.geom, 0.01);

SELECT d.id_com_del into NEW.id_com_del, d.commune_deleguee_nom into NEW.commune_deleguee_nom
FROM adresse.commune_deleguee d
WHERE ST_DWithin(NEW.geom, d.geom, 0.01);

NEW.numero = 99999 ;
NEW.date_der_maj = NOW();
RETURN NEW;
Expand All @@ -75,7 +75,7 @@ CREATE FUNCTION adresse.get_code_postal()
AS $BODY$
DECLARE
BEGIN
NEW.code_postal = (SELECT a.cp FROM adresse.codes_postaux a WHERE ST_intersects(NEW.geom, a.geom));
SELECT a.cp into NEW.code_postal FROM adresse.codes_postaux a WHERE ST_intersects(NEW.geom, a.geom));
RETURN NEW;
END;
$BODY$;
Expand All @@ -91,10 +91,10 @@ CREATE FUNCTION adresse.get_commune_deleguee()
AS $BODY$
DECLARE
BEGIN
NEW.commune_deleguee_nom = (SELECT a.commune_deleguee_nom FROM adresse.commune_deleguee a
WHERE ST_intersects(NEW.geom, a.geom));
NEW.commune_deleguee_insee = (SELECT b.insee_code FROM adresse.commune_deleguee b
WHERE ST_Intersects(NEW.geom, b.geom));
SELECT a.commune_deleguee_nom into NEW.commune_deleguee_nom,
a.commune_deleguee_insee into NEW.commune_deleguee_insee
FROM adresse.commune_deleguee a
WHERE ST_intersects(NEW.geom, a.geom);
RETURN NEW;
END;
$BODY$;
Expand All @@ -109,10 +109,9 @@ CREATE FUNCTION adresse.get_commune_insee()
AS $BODY$
DECLARE
BEGIN
NEW.commune_insee = (SELECT a.insee_code FROM adresse.commune a
WHERE ST_intersects(NEW.geom, a.geom));
NEW.commune_nom = (SELECT b.commune_nom FROM adresse.commune b
WHERE ST_Intersects(NEW.geom, b.geom));
SELECT a.insee_code into NEW.commune_insee, a.commune_nom into NEW.commune_nom
FROM adresse.commune a
WHERE ST_intersects(NEW.geom, a.geom);

RETURN NEW;
END;
Expand Down Expand Up @@ -161,7 +160,7 @@ CREATE TABLE adresse.codes_postaux
(
id bigint NOT NULL,
geom geometry(MultiPolygon,2154),
cp integer,
cp text,
CONSTRAINT codes_postaux_pkey PRIMARY KEY (id)
);

Expand All @@ -172,10 +171,10 @@ CREATE TABLE adresse.codes_postaux
-- commune

ALTER TABLE adresse.commune
ADD COLUMN calvados_ingenierie boolean;
ADD COLUMN acc_ingenierie_publique boolean;

ALTER TABLE adresse.commune
ADD COLUMN filtrage character varying(255) COLLATE pg_catalog."default";
ADD COLUMN key_lizmap_filter character varying(255) COLLATE pg_catalog."default";

ALTER TABLE adresse.commune
ADD COLUMN diffusion_sna boolean;
Expand Down Expand Up @@ -297,24 +296,6 @@ CREATE TABLE adresse.lieux_dits
--lieux_dits_id_ld_seq
ALTER SEQUENCE adresse.lieux_dits_id_ld_seq OWNED BY adresse.lieux_dits.id_ld;




-- parcelle_fid_seq
ALTER SEQUENCE adresse.parcelle_fid_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


-- parcelle_fid_seq
ALTER SEQUENCE adresse.parcelle_fid_seq OWNED BY adresse.parcelle.fid;




-- point_adresse
ALTER TABLE adresse.point_adresse
ALTER COLUMN valide SET NOT NULL;
Expand Down Expand Up @@ -516,45 +497,7 @@ UNION

ALTER VIEW adresse.vue_com RENAME TO v_commune;





--v_export_pts

CREATE OR REPLACE VIEW adresse.v_export_pts
AS
SELECT pa.commune_insee AS "Code INSEE",
pa.commune_nom AS "Commune",
pa.commune_deleguee_insee AS "Code INSEE commune déléguée",
pa.commune_deleguee_nom AS "Commune déléguée",
pa.numero AS "Numéro",
pa.suffixe AS "Suffixe",
voie.typologie AS "Typologie",
voie.nom AS "Nom de la voie",
voie.nom_complet AS "Nom complet",
pa.adresse_complete AS "Adresse complète",
pa.lieudit_complement_nom AS "Lieu-dit",
pa.code_postal AS "Code postal",
pa.type_pos AS "Position",
pa.valide AS "Point validé",
pa.achat_plaque_numero AS "Achat de la plaque",
pa.commune_nom AS "Source",
pa.date_modif AS "Date dernière modification",
st_x(pa.geom) AS "X",
st_y(pa.geom) AS "Y",
st_x(st_transform(pa.geom, 4326)) AS "Longitude",
st_y(st_transform(pa.geom, 4326)) AS "Latitude"
FROM adresse.point_adresse pa
LEFT JOIN adresse.voie ON voie.id_voie = pa.id_voie
WHERE pa.commune_insee = '14660'::bpchar
ORDER BY voie.nom_complet, pa.numero;



--v_export_voies


CREATE OR REPLACE VIEW adresse.v_export_voies
AS
SELECT DISTINCT voie.id_voie AS "ID",
Expand Down

0 comments on commit 3824e6c

Please sign in to comment.