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 Jul 23, 2021
1 parent 1ffb43f commit 86a81e6
Show file tree
Hide file tree
Showing 10 changed files with 584 additions and 251 deletions.
127 changes: 116 additions & 11 deletions gestion_base_adresse/install/sql/adresse/10_FUNCTION.sql
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,77 @@ END;
$$;


-- check_impair(integer)
CREATE FUNCTION adresse.check_impair(nombre integer) RETURNS boolean
LANGUAGE plpgsql
AS $$
/* Cette fonction retourne true (vrai) si le nombre passé en argument est impair
Exemple : SELECT checkimpair(12);
false
*/
BEGIN
return nombre % 2!=0;
END;
$$;


-- creation_adresse()
CREATE FUNCTION adresse.creation_adresse() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
NEW.creation_adresse = 'true';
RETURN NEW;
END;
$$;


-- edit_point_adresse()
CREATE FUNCTION adresse.edit_point_adresse() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
IF (TG_OP == 'INSERT') THEN
INSERT INTO adresse.point_adresse SELECT NEW.*;
ELSEIF (TG_OP = 'UPDATE') THEN
UPDATE adresse.point_adresse SET OLD = NEW WHERE id_point = NEW.id_point;
ELSEIF (TG_OP = 'DELETE') THEN
DELETE FROM adresse.point_adresse WHERE id_point = NEW.id_point;
END IF;
RETURN NEW;
END;
$$;


-- get_code_postal()
CREATE FUNCTION adresse.get_code_postal() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
SELECT a.cp into NEW.code_postal FROM adresse.codes_postaux a WHERE ST_intersects(NEW.geom, a.geom);
RETURN NEW;
END;
$$;


-- get_commune()
CREATE FUNCTION adresse.get_commune() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
leid integer;
BEGIN
SELECT c.id_com into leid FROM adresse.commune c WHERE st_intersects(New.geom,c.geom);
NEW.id_commune = leid;
RETURN NEW;
END;
$$;


-- get_id_voie(public.geometry)
CREATE FUNCTION adresse.get_id_voie(pgeom public.geometry) RETURNS integer
LANGUAGE plpgsql
Expand Down Expand Up @@ -287,6 +358,35 @@ END;
$$;


-- lieux_dits()
CREATE FUNCTION adresse.lieux_dits() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
SELECT c.id_com into NEW.id_com
FROM adresse.commune c
WHERE ST_DWithin(NEW.geom, d.geom, 0.01);

SELECT 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
FROM adresse.commune_deleguee d
WHERE ST_DWithin(NEW.geom, d.geom, 0.01);

SELECT 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;
END;
$$;


-- longueur_voie()
CREATE FUNCTION adresse.longueur_voie() RETURNS trigger
LANGUAGE plpgsql
Expand Down Expand Up @@ -453,22 +553,15 @@ END;
$$;


-- update_commune()
CREATE FUNCTION adresse.update_commune() RETURNS trigger
-- update_appartenir_com()
CREATE FUNCTION adresse.update_appartenir_com() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
leid integer;
BEGIN
IF (TG_TABLE_NAME = 'voie') THEN
INSERT INTO adresse.appartenir_com(id_voie, id_com) SELECT NEW.id_voie, c.id_com from adresse.commune c where ST_intersects(NEW.geom, c.geom);
RETURN NEW;
ELSIF (TG_TABLE_NAME = 'point_adresse') THEN
SELECT c.id_com into leid FROM adresse.commune c WHERE st_intersects(New.geom,c.geom);
NEW.id_commune = leid;
RETURN NEW;
END IF;
RETURN NULL;
INSERT INTO adresse.appartenir_com(id_voie, id_com) SELECT NEW.id_voie, c.id_com from adresse.commune c where ST_intersects(NEW.geom, c.geom);
RETURN NEW;
END;
$$;

Expand Down Expand Up @@ -501,6 +594,18 @@ END;
$$;


-- voie_nom_complet_maj()
CREATE FUNCTION adresse.voie_nom_complet_maj() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
NEW.nom_complet_maj = Translate(Upper(Concat(NEW.typologie, ' ', NEW.nom)), 'ÀÉÈÊËÏÎÔÖÜÛÇ'::text, 'AEEEEIIOOUUC'::text);
RETURN NEW;
END;
$$;


--
-- PostgreSQL database dump complete
--
Expand Down
128 changes: 124 additions & 4 deletions gestion_base_adresse/install/sql/adresse/20_TABLE_SEQUENCE_DEFAULT.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

-- alerte_ddfip_id_seq
CREATE SEQUENCE adresse.alerte_ddfip_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
MAXVALUE 2147483647
CACHE 1;


SET default_tablespace = '';

SET default_with_oids = false;
Expand All @@ -27,6 +36,14 @@ CREATE TABLE adresse.appartenir_com (
);


-- codes_postaux
CREATE TABLE adresse.codes_postaux (
id bigint NOT NULL,
geom public.geometry(MultiPolygon,2154),
cp text
);


-- commune
CREATE TABLE adresse.commune (
id_com integer NOT NULL,
Expand All @@ -50,7 +67,15 @@ CREATE TABLE adresse.commune (
geom public.geometry(MultiPolygon,2154),
adresse_mairie text,
code_postal text,
maire text
maire text,
acc_ingenierie_publique boolean,
key_lizmap_filter character varying(255),
diffusion_sna boolean,
date_sna date,
courrier_president character varying(255),
poste text,
nb_locaux integer,
osm boolean
);


Expand Down Expand Up @@ -116,6 +141,91 @@ CREATE SEQUENCE adresse.document_id_doc_seq
ALTER SEQUENCE adresse.document_id_doc_seq OWNED BY adresse.document.id_doc;


-- import_ban
CREATE TABLE adresse.import_ban (
id_ban_position text,
id_ban_adresse text,
cle_interop text,
id_ban_group text,
id_fantoir text,
numero smallint,
suffixe text,
nom_voie text,
code_postal text,
nom_commune text,
code_insee text,
nom_complementaire text,
x double precision,
y double precision,
lon text,
lat text,
typ_loc text,
source text,
date_der_maj text,
geom public.geometry(Point,2154)
);


-- import_ban_etat_commune
CREATE TABLE adresse.import_ban_etat_commune (
region smallint,
departement smallint,
code_commune integer,
nom_commune text,
population bigint,
type_composition text,
nb_lieux_dits integer,
nb_voies integer,
nb_numeros integer,
analyse_adressage_nb_adresses_attendues integer,
analyse_adressage_ratio integer,
analyse_adressage_deficit_adresses smallint
);


-- import_ban_lo
CREATE TABLE adresse.import_ban_lo (
id text,
numero text,
rep text,
nom_voie text,
code_postal text,
code_insee text,
nom_commune text,
x text,
y text,
geom public.geometry(Point,2154)
);


-- lieux_dits
CREATE TABLE adresse.lieux_dits (
id_ld integer NOT NULL,
geom public.geometry(Point,2154),
nom_ld text,
numero integer,
integration_ban boolean,
id_com integer NOT NULL,
commune_nom text,
date_der_maj date,
id_com_del integer,
commune_deleguee_nom text
);


-- lieux_dits_id_ld_seq
CREATE SEQUENCE adresse.lieux_dits_id_ld_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


-- lieux_dits_id_ld_seq
ALTER SEQUENCE adresse.lieux_dits_id_ld_seq OWNED BY adresse.lieux_dits.id_ld;


-- metadata
CREATE TABLE adresse.metadata (
id integer NOT NULL,
Expand Down Expand Up @@ -190,7 +300,11 @@ CREATE TABLE adresse.point_adresse (
id_voie integer,
id_commune integer,
id_parcelle integer,
valide boolean DEFAULT true
valide boolean DEFAULT true NOT NULL,
verif_terrain boolean DEFAULT false NOT NULL,
complement_adresse character varying(255),
lieudit_complement_nom character varying(255),
creation_adresse boolean
);


Expand Down Expand Up @@ -223,7 +337,7 @@ CREATE TABLE adresse.voie (
nom text NOT NULL,
nom_complet text,
type_num text,
statut_voie_num boolean DEFAULT true NOT NULL,
statut_voie_num boolean DEFAULT false NOT NULL,
statut_voie boolean DEFAULT false NOT NULL,
sens_numerotation boolean DEFAULT false NOT NULL,
achat_plaque_voie boolean DEFAULT false NOT NULL,
Expand All @@ -235,7 +349,9 @@ CREATE TABLE adresse.voie (
longueur integer,
code_fantoir integer,
delib boolean,
geom public.geometry(LineString,2154)
geom public.geometry(LineString,2154),
nb_panneaux smallint,
nom_complet_maj text
);


Expand Down Expand Up @@ -264,6 +380,10 @@ ALTER TABLE ONLY adresse.commune_deleguee ALTER COLUMN id_com_del SET DEFAULT ne
ALTER TABLE ONLY adresse.document ALTER COLUMN id_doc SET DEFAULT nextval('adresse.document_id_doc_seq'::regclass);


-- lieux_dits id_ld
ALTER TABLE ONLY adresse.lieux_dits ALTER COLUMN id_ld SET DEFAULT nextval('adresse.lieux_dits_id_ld_seq'::regclass);


-- metadata id
ALTER TABLE ONLY adresse.metadata ALTER COLUMN id SET DEFAULT nextval('adresse.metadata_id_seq'::regclass);

Expand Down
Loading

0 comments on commit 86a81e6

Please sign in to comment.