Skip to content

Commit 80835ba

Browse files
committed
osm2pgsql-replication: add '--middle-schema'
1 parent 41f2e56 commit 80835ba

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scripts/osm2pgsql-replication

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ def connect(args):
8686
host=args.host, port=args.port)
8787

8888

89-
def table_exists(conn, table_name):
89+
def table_exists(conn, table_name, schema_name=None):
9090
with conn.cursor() as cur:
91-
cur.execute('SELECT * FROM pg_tables where tablename = %s', (table_name, ))
91+
if schema_name is not None:
92+
cur.execute('SELECT * FROM pg_tables where tablename = %s and schemaname = %s ', (table_name, schema_name))
93+
else:
94+
cur.execute('SELECT * FROM pg_tables where tablename = %s', (table_name, ))
9295
return cur.rowcount > 0
9396

9497

@@ -206,7 +209,7 @@ def status(conn, args):
206209

207210
results = {}
208211

209-
if not table_exists(conn, args.table_name):
212+
if not table_exists(conn, args.table_name, args.middle_schema):
210213
results['status'] = 1
211214
results['error'] = "Cannot find replication status table. Run 'osm2pgsql-replication init' first."
212215
else:
@@ -350,7 +353,7 @@ def update(conn, args):
350353
may be missing in the rare case that the replication service stops responding
351354
after the updates have been downloaded.
352355
"""
353-
if not table_exists(conn, args.table_name):
356+
if not table_exists(conn, args.table_name, args.middle_schema):
354357
LOG.fatal("Cannot find replication status table. "
355358
"Run 'osm2pgsql-replication init' first.")
356359
return 1
@@ -459,6 +462,8 @@ def get_parser():
459462
help='Database server port')
460463
group.add_argument('-p', '--prefix', metavar='PREFIX', default='planet_osm',
461464
help="Prefix for table names (default 'planet_osm')")
465+
group.add_argument('--middle-schema', metavar='MIDDLE_SCHEMA', default='public',
466+
help='Name of the schema to store the table for the replication state in')
462467

463468
# Arguments for init
464469
cmd = subs.add_parser('init', parents=[default_args],
@@ -532,7 +537,7 @@ def main():
532537
level=max(4 - args.verbose, 1) * 10)
533538

534539
args.table_name = f'{args.prefix}_replication_status'
535-
args.table = sql.Identifier(args.table_name)
540+
args.table = sql.Identifier(args.middle_schema, args.table_name)
536541

537542
conn = connect(args)
538543

0 commit comments

Comments
 (0)