1
1
#!/usr/bin/env python3
2
2
3
- import argparse
3
+ from argparse import ArgumentParser , BooleanOptionalAction
4
4
from pathlib import Path
5
5
from typing import Optional
6
6
@@ -31,20 +31,23 @@ def run_sql(sql: str, pg_service: str, variables: dict = None):
31
31
def create_app (
32
32
srid : int = 2056 ,
33
33
pg_service : str = "pg_tww" ,
34
+ drop_schema : Optional [bool ] = False ,
34
35
tww_reach_extra : Optional [Path ] = None ,
35
36
tww_wastewater_structure_extra : Optional [Path ] = None ,
36
37
):
37
38
"""
38
39
Creates the schema tww_app for TEKSI Wastewater & GEP
39
40
:param srid: the EPSG code for geometry columns
41
+ :param drop_schema: will drop schema tww_app if it exists
40
42
:param pg_service: the PostgreSQL service, if not given it will be determined from environment variable in Pirogue
41
43
:param tww_reach_extra: YAML file path of the definition of additional columns for vw_tww_reach view
42
44
:param tww_wastewater_structure_extra: YAML file path of the definition of additional columns for vw_tww_wastewater_structure_extra view
43
45
"""
44
46
cwd = Path (__file__ ).parent .resolve ()
45
47
variables = {"SRID" : srid }
46
48
47
- run_sql ("DROP SCHEMA IF EXISTS tww_app CASCADE;" , pg_service )
49
+ if drop_schema :
50
+ run_sql ("DROP SCHEMA IF EXISTS tww_app CASCADE;" , pg_service )
48
51
49
52
run_sql ("CREATE SCHEMA tww_app;" , pg_service )
50
53
@@ -208,7 +211,7 @@ def create_app(
208
211
209
212
210
213
if __name__ == "__main__" :
211
- parser = argparse . ArgumentParser ()
214
+ parser = ArgumentParser ()
212
215
parser .add_argument ("-p" , "--pg_service" , help = "postgres service" )
213
216
parser .add_argument (
214
217
"-s" , "--srid" , help = "SRID EPSG code, defaults to 2056" , type = int , default = 2056
@@ -221,11 +224,19 @@ def create_app(
221
224
"--tww_reach_extra" ,
222
225
help = "YAML definition file path for additions to vw_tww_reach view" ,
223
226
)
227
+ parser .add_argument (
228
+ "-d" ,
229
+ "--drop-schema" ,
230
+ help = "Drops cascaded any existing tww_app schema" ,
231
+ default = False ,
232
+ action = BooleanOptionalAction ,
233
+ )
224
234
args = parser .parse_args ()
225
235
226
236
create_app (
227
237
args .srid ,
228
238
args .pg_service ,
239
+ drop_schema = args .drop_schema ,
229
240
tww_reach_extra = args .tww_reach_extra ,
230
241
tww_wastewater_structure_extra = args .tww_wastewater_structure_extra ,
231
242
)
0 commit comments