Skip to content

Commit 45843be

Browse files
Merge pull request #316 from rustprooflabs/remove-schema-name-option
Remove `--schema-name` option
2 parents a97c6ff + a57d5bd commit 45843be

File tree

3 files changed

+17
-54
lines changed

3 files changed

+17
-54
lines changed

docker/db.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,14 @@ def pg_isready():
182182
return True
183183

184184

185-
def prepare_pgosm_db(skip_qgis_style, db_path, import_mode, schema_name):
185+
def prepare_pgosm_db(skip_qgis_style, db_path, import_mode):
186186
"""Runs through series of steps to prepare database for PgOSM.
187187
188188
Parameters
189189
--------------------------
190190
skip_qgis_style : bool
191191
db_path : str
192192
import_mode : import_mode.ImportMode
193-
schema_name : str
194193
"""
195194
if pg_conn_parts()['pg_host'] == 'localhost':
196195
drop_it = True
@@ -224,8 +223,7 @@ def prepare_pgosm_db(skip_qgis_style, db_path, import_mode, schema_name):
224223
else:
225224
LOGGER.info('Loading QGIS styles')
226225
qgis_styles.load_qgis_styles(db_path=db_path,
227-
db_name=pg_conn_parts()['pg_db'],
228-
schema_name=schema_name)
226+
db_name=pg_conn_parts()['pg_db'])
229227

230228

231229

@@ -553,33 +551,18 @@ def osm2pgsql_replication_finish(skip_nested):
553551
sys.exit(f'{err_msg} - Check the log output for details.')
554552

555553

556-
def rename_schema(schema_name):
557-
"""Renames default schema name "osm" to `schema_name`
558-
559-
Returns
560-
----------------------------
561-
schema_name : str
562-
"""
563-
LOGGER.info(f'Renaming schema from osm to {schema_name}')
564-
sql_raw = f'ALTER SCHEMA osm RENAME TO {schema_name} ;'
565-
566-
with get_db_conn(conn_string=os.environ['PGOSM_CONN']) as conn:
567-
cur = conn.cursor()
568-
cur.execute(sql_raw)
569-
570-
571-
def run_pg_dump(export_path, skip_qgis_style, schema_name):
554+
def run_pg_dump(export_path, skip_qgis_style):
572555
"""Runs pg_dump to save processed data to load into other PostGIS DBs.
573556
574557
Parameters
575558
---------------------------
576559
export_path : str
577560
Absolute path to output .sql file
578561
skip_qgis_style : bool
579-
schema_name : str
580562
"""
581563
logger = logging.getLogger('pgosm-flex')
582564
conn_string = os.environ['PGOSM_CONN']
565+
schema_name = 'osm'
583566

584567
if skip_qgis_style:
585568
logger.info(f'Running pg_dump (only {schema_name} schema)')

docker/pgosm_flex.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
default=False,
5858
is_flag=True,
5959
help='Replication mode enables updates via osm2pgsql-replication.')
60-
@click.option('--schema-name', required=False,
61-
default='osm',
62-
help="Change the final schema name, defaults to 'osm'.")
6360
@click.option('--skip-nested',
6461
default=False,
6562
is_flag=True,
@@ -78,7 +75,7 @@
7875
help='EXPERIMENTAL - Wrap around osm2pgsql create v. append modes, without using osm2pgsql-replication.')
7976
def run_pgosm_flex(ram, region, subregion, debug,
8077
input_file, layerset, layerset_path, language, pg_dump,
81-
pgosm_date, replication, schema_name, skip_nested,
78+
pgosm_date, replication, skip_nested,
8279
skip_qgis_style, srid, sp_gist, update):
8380
"""Run PgOSM Flex within Docker to automate osm2pgsql flex processing.
8481
"""
@@ -87,12 +84,6 @@ def run_pgosm_flex(ram, region, subregion, debug,
8784
logger = logging.getLogger('pgosm-flex')
8885
logger.info('PgOSM Flex starting...')
8986

90-
# Input validation
91-
if schema_name != 'osm' and replication:
92-
err_msg = 'Replication mode with custom schema name currently not supported'
93-
logger.error(err_msg)
94-
sys.exit(err_msg)
95-
9687
if replication and (update is not None):
9788
err_msg = 'The --replication and --update features are mutually exclusive. Use one or the other.'
9889
logger.error(err_msg)
@@ -130,8 +121,7 @@ def run_pgosm_flex(ram, region, subregion, debug,
130121

131122
db.prepare_pgosm_db(skip_qgis_style=skip_qgis_style,
132123
db_path=paths['db_path'],
133-
import_mode=import_mode,
134-
schema_name=schema_name)
124+
import_mode=import_mode)
135125

136126
# There's probably a better way to get this data out, but this worked right
137127
# away and I'm moving on. I'm breaking enough other things that this seemed
@@ -174,14 +164,10 @@ def run_pgosm_flex(ram, region, subregion, debug,
174164

175165
db.log_import_message(import_id=import_id, msg='Completed')
176166

177-
if schema_name != 'osm':
178-
db.rename_schema(schema_name)
179-
180167
dump_database(input_file=input_file,
181168
out_path=paths['out_path'],
182169
pg_dump=pg_dump,
183-
skip_qgis_style=skip_qgis_style,
184-
schema_name=schema_name)
170+
skip_qgis_style=skip_qgis_style)
185171

186172
logger.info('PgOSM Flex complete!')
187173

@@ -504,7 +490,7 @@ def run_post_processing(flex_path, skip_nested, import_mode):
504490
return True
505491

506492

507-
def dump_database(input_file, out_path, pg_dump, skip_qgis_style, schema_name):
493+
def dump_database(input_file, out_path, pg_dump, skip_qgis_style):
508494
"""Runs pg_dump when necessary to export the processed OpenStreetMap data.
509495
510496
Parameters
@@ -513,15 +499,13 @@ def dump_database(input_file, out_path, pg_dump, skip_qgis_style, schema_name):
513499
out_path : str
514500
pg_dump : bool
515501
skip_qgis_style : bool
516-
schema_name : str
517502
"""
518503
if pg_dump:
519504
export_filename = get_export_filename(input_file)
520505
export_path = get_export_full_path(out_path, export_filename)
521506

522507
db.run_pg_dump(export_path=export_path,
523-
skip_qgis_style=skip_qgis_style,
524-
schema_name=schema_name)
508+
skip_qgis_style=skip_qgis_style)
525509
else:
526510
logging.getLogger('pgosm-flex').info('Skipping pg_dump')
527511

docker/qgis_styles.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,21 @@
1010
LOGGER = logging.getLogger('pgosm-flex')
1111

1212

13-
def load_qgis_styles(db_path, db_name, schema_name):
13+
def load_qgis_styles(db_path, db_name):
1414
"""Loads QGIS style data for easy formatting of most common layers.
1515
1616
Parameters
1717
-------------------------
1818
db_path : str
1919
Base path to pgosm-flex/db directory
2020
db_name : str
21-
schema_name : str
2221
"""
2322
LOGGER.info(f'Load QGIS styles to database {db_name}...')
2423
conn_string = os.environ['PGOSM_CONN']
2524

2625
create_layer_style_table(db_path=db_path, conn_string=conn_string)
2726
populate_layer_style_staging(db_path=db_path, conn_string=conn_string)
28-
update_styles_db_name(db_name=db_name, schema_name=schema_name,
29-
conn_string=conn_string)
27+
update_styles_db_name(db_name=db_name, conn_string=conn_string)
3028
load_staging_to_prod(db_path=db_path, conn_string=conn_string)
3129

3230

@@ -102,29 +100,27 @@ def load_staging_to_prod(db_path, conn_string):
102100
LOGGER.debug('QGIS Style staging table cleaned')
103101

104102

105-
def update_styles_db_name(db_name, schema_name, conn_string):
103+
def update_styles_db_name(db_name, conn_string):
106104
"""
107105
Parameters
108106
----------------------
109107
db_name : str
110-
schema_name : str
111108
conn_string : str
112109
"""
113-
if db_name == 'pgosm' and schema_name == 'osm':
114-
LOGGER.debug('Database name and schema name set to defaults. Update to layer styles not necessary')
110+
if db_name == 'pgosm':
111+
LOGGER.debug('Database name set to defaults. Update to layer styles not necessary')
115112
return
116113

117114
sql_raw = """
118115
UPDATE public.layer_styles_staging
119-
SET f_table_catalog = %(db_name)s ,
120-
f_table_schema = %(schema_name)s
116+
SET f_table_catalog = %(db_name)s
121117
;
122118
"""
123-
params = {'db_name': db_name, 'schema_name': schema_name}
119+
params = {'db_name': db_name}
124120
with db.get_db_conn(conn_string=conn_string) as conn:
125121
cur = conn.cursor()
126122
cur.execute(sql_raw, params=params)
127123
conn.commit()
128124

129-
LOGGER.info(f'Updated QGIS layer styles for {db_name}.{schema_name}')
125+
LOGGER.info(f'Updated QGIS layer styles for database {db_name}')
130126

0 commit comments

Comments
 (0)