init depot renew

This commit is contained in:
2026-09-22 11:58:57 +02:00
commit e9fa6a7309
205 changed files with 39721 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from sqlalchemy.sql import text
from sqlalchemy.engine import URL
from sqlalchemy import create_engine
import pandas as pd
import geopandas as gpd
from pycen import con_cad
# pg_dump -h 91.134.194.221 -d cadastre -U cgeier --schema="38_202207" -s > 38_202207.sql
# psql -h 91.134.194.221 -U cgeier -d cadastre -a -f 38_202207.sql
lst_sch = con_cad.dialect.get_schema_names(con_cad)
lst_sch = ['07_202207','26_202207','42_202207']
for s in lst_sch:
lst_tab = con_cad.dialect.get_table_names(con_cad,s)
for t in lst_tab:
lst_col = con_cad.dialect.get_columns(con_cad,t,s)
lst_col = [x['name'] for x in lst_col ]
if 'geom' in lst_col:
df = gpd.read_postgis('SELECT * FROM "{sch}".{tab}'.format(sch=s,tab=t),con_cad)
if df.empty:
continue
df.to_postgis(t,con_cad,'xx_202207',if_exists='append',index=False)
else :
df = pd.read_sql_table(t,con_cad,s)
if df.empty:
continue
df.to_sql(t,con_cad,'xx_202207',if_exists='append',index=False)
print("{sch}.{tab}".format(sch=s,tab=t))
+11
View File
@@ -0,0 +1,11 @@
# RESTORE AU NOM DE LA BDD ORIGINE
# pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser dbname
# pg_dump -C -h 172.17.0.2 -U postgres -d postgres --schema="07_202107" | psql -h 91.134.194.221 -U cgeier -d bd_cen
# RESTORE AU NOM DE LA BDD CIBLE
# pg_dump -C -h 172.17.0.2 -U postgres -d postgres --schema="*_202501" --format=custom | pg_restore -h 91.134.194.221 -U cgeier --dbname="cadastre"
# export PGPASSWORD="xxxxxx";pg_dump -C -h localhost -U cgeier -d cadastre --schema="*_202603" | psql -h 91.134.194.221 -U cgeier --dbname="bd_cen" -W
# export PGPASSWORD="xxxxxx";pg_dump -C -h 91.134.194.221 -U cgeier -d cadastre --schema="*_202603" --format=custom | pg_restore -h 91.134.194.221 -U cgeier --dbname="bd_cen"
+70
View File
@@ -0,0 +1,70 @@
from pycen import con_fon
view_typprop_x = '''
DROP VIEW IF EXISTS {sch}.{view};
CREATE OR REPLACE VIEW {sch}.{view}
AS
SELECT
p.par_id,
p.codcom,
p.ccopre,
p.ccosec,
p.dnupla,
p.dparpi,
p.dcntpa,
p.ccocomm,
p.ccoprem,
p.ccosecm,
p.dnuplam,
p.type,
p.geom,
typprop_lib,
typprop,
array_agg(dnuper) dnuper,
array_agg(ddenom) ddenom
FROM "{sch}".parcelles{_cen} p
LEFT JOIN "{sch}".d_typprop USING (typprop_id)
LEFT JOIN "{sch}".lots{_cen} USING (par_id)
LEFT JOIN "{sch}".cadastre{_cen} USING (lot_id)
LEFT JOIN "{sch}".cptprop{_cen} USING (dnupro)
LEFT JOIN "{sch}".r_prop_cptprop{_cen} USING (dnupro)
LEFT JOIN "{sch}".proprios{_cen} USING (dnuper)
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
'''
grant = """
GRANT ALL ON TABLE {sch}.{view} TO grp_admin;
GRANT SELECT ON TABLE {sch}.{view} TO grp_consult;
"""
with con_fon.begin() as cnx:
cnx.execute(view_typprop_x.format(sch='cadastre', _cen= '', view='v_prop_parcelles'))
cnx.execute(view_typprop_x.format(sch='cadastre', _cen= '_cen', view='v_prop_parcelles_cen'))
cnx.execute(grant.format(sch='cadastre', view='v_prop_parcelles'))
cnx.execute(grant.format(sch='cadastre', view='v_prop_parcelles_cen'))
view_natcult_x = '''
DROP VIEW IF EXISTS {sch}.{view};
CREATE OR REPLACE VIEW {sch}.{view}
AS
SELECT
p.par_id,
p.geom,
array_agg(d_dsgrpf.natcult_ssgrp) natcult_ssgrp,
array_agg(d_cgrnum.natcult_grp) natcult_grp,
array_agg(d_cnatsp.natcult_natspe) natcult_natspe
FROM "{sch}".parcelles{_cen} p
LEFT JOIN "{sch}".lots{_cen} USING (par_id)
LEFT JOIN "{sch}".lots_natcult{_cen} USING (lot_id)
LEFT JOIN "{sch}".d_dsgrpf USING (dsgrpf)
LEFT JOIN "{sch}".d_cgrnum USING (cgrnum)
LEFT JOIN "{sch}".d_cnatsp USING (cnatsp)
GROUP BY par_id
'''
with con_fon.begin() as cnx:
cnx.execute(view_natcult_x.format(sch='cadastre', _cen= '', view='v_natcult'))
cnx.execute(view_natcult_x.format(sch='cadastre', _cen= '_cen', view='v_natcult_cen'))
cnx.execute(grant.format(sch='cadastre', view='v_natcult'))
cnx.execute(grant.format(sch='cadastre', view='v_natcult_cen'))