Skip to content

Commit 752a6ed

Browse files
committed
add option to drop schema
1 parent c0e21e9 commit 752a6ed

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

datamodel/app/create_app.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
import argparse
3+
from argparse import ArgumentParser, BooleanOptionalAction
44
from pathlib import Path
55
from typing import Optional
66

@@ -31,20 +31,23 @@ def run_sql(sql: str, pg_service: str, variables: dict = None):
3131
def create_app(
3232
srid: int = 2056,
3333
pg_service: str = "pg_tww",
34+
drop_schema: Optional[bool] = False,
3435
tww_reach_extra: Optional[Path] = None,
3536
tww_wastewater_structure_extra: Optional[Path] = None,
3637
):
3738
"""
3839
Creates the schema tww_app for TEKSI Wastewater & GEP
3940
:param srid: the EPSG code for geometry columns
41+
:param drop_schema: will drop schema tww_app if it exists
4042
:param pg_service: the PostgreSQL service, if not given it will be determined from environment variable in Pirogue
4143
:param tww_reach_extra: YAML file path of the definition of additional columns for vw_tww_reach view
4244
:param tww_wastewater_structure_extra: YAML file path of the definition of additional columns for vw_tww_wastewater_structure_extra view
4345
"""
4446
cwd = Path(__file__).parent.resolve()
4547
variables = {"SRID": srid}
4648

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)
4851

4952
run_sql("CREATE SCHEMA tww_app;", pg_service)
5053

@@ -208,7 +211,7 @@ def create_app(
208211

209212

210213
if __name__ == "__main__":
211-
parser = argparse.ArgumentParser()
214+
parser = ArgumentParser()
212215
parser.add_argument("-p", "--pg_service", help="postgres service")
213216
parser.add_argument(
214217
"-s", "--srid", help="SRID EPSG code, defaults to 2056", type=int, default=2056
@@ -221,11 +224,19 @@ def create_app(
221224
"--tww_reach_extra",
222225
help="YAML definition file path for additions to vw_tww_reach view",
223226
)
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+
)
224234
args = parser.parse_args()
225235

226236
create_app(
227237
args.srid,
228238
args.pg_service,
239+
drop_schema=args.drop_schema,
229240
tww_reach_extra=args.tww_reach_extra,
230241
tww_wastewater_structure_extra=args.tww_wastewater_structure_extra,
231242
)

datamodel/scripts/setup.sh

-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/changelogs/0001/52_dss1
3535
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/12_0_roles.sql
3636
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/12_1_roles.sql
3737

38-
psql "service=${PGSERVICE}" -c "CREATE SCHEMA IF NOT EXISTS tww_app;"
39-
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/app/symbology_functions.sql
40-
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/app/reach_direction_change.sql -v SRID=$SRID
41-
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/app/14_geometry_functions.sql -v SRID=$SRID
42-
4338
${DIR}/app/create_app.py --pg_service ${PGSERVICE} --srid ${SRID}

0 commit comments

Comments
 (0)