Skip to content

Commit 45ea63d

Browse files
authored
Merge pull request #2038 from lonvia/schma-options
Add --schema option to osm2pgsql-replication
2 parents 50506ab + e9a1182 commit 45ea63d

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

docs/osm2pgsql-replication.1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ how to use osm2pgsql\-replication.
3939
.SH OPTIONS 'osm2pgsql-replication init'
4040
usage: osm2pgsql-replication init [-h] [-q] [-v] [-d DB] [-U NAME] [-H HOST]
4141
[-P PORT] [-p PREFIX]
42-
[--middle-schema MIDDLE_SCHEMA]
42+
[--middle-schema SCHEMA] [--schema SCHEMA]
4343
[--osm-file FILE | --server URL]
4444
[--start-at TIME]
4545

@@ -136,9 +136,13 @@ Database server port
136136
Prefix for table names (default 'planet_osm')
137137

138138
.TP
139-
\fB\-\-middle\-schema\fR MIDDLE_SCHEMA
139+
\fB\-\-middle\-schema\fR SCHEMA
140140
Name of the schema to store the table for the replication state in
141141

142+
.TP
143+
\fB\-\-schema\fR SCHEMA
144+
Name of the schema for the database
145+
142146
.TP
143147
\fB\-\-osm\-file\fR FILE
144148
Get replication information from the given file.
@@ -253,14 +257,19 @@ Database server port
253257
Prefix for table names (default 'planet_osm')
254258

255259
.TP
256-
\fB\-\-middle\-schema\fR MIDDLE_SCHEMA
260+
\fB\-\-middle\-schema\fR SCHEMA
257261
Name of the schema to store the table for the replication state in
258262

263+
.TP
264+
\fB\-\-schema\fR SCHEMA
265+
Name of the schema for the database
266+
259267

260268
.SH OPTIONS 'osm2pgsql-replication status'
261269
usage: osm2pgsql-replication status [-h] [-q] [-v] [-d DB] [-U NAME] [-H HOST]
262270
[-P PORT] [-p PREFIX]
263-
[--middle-schema MIDDLE_SCHEMA] [--json]
271+
[--middle-schema SCHEMA] [--schema SCHEMA]
272+
[--json]
264273

265274
Print information about the current replication status, optionally as JSON.
266275
.br
@@ -372,9 +381,13 @@ Database server port
372381
Prefix for table names (default 'planet_osm')
373382

374383
.TP
375-
\fB\-\-middle\-schema\fR MIDDLE_SCHEMA
384+
\fB\-\-middle\-schema\fR SCHEMA
376385
Name of the schema to store the table for the replication state in
377386

387+
.TP
388+
\fB\-\-schema\fR SCHEMA
389+
Name of the schema for the database
390+
378391
.SH SEE ALSO
379392
* osm2pgsql website (https://osm2pgsql.org)
380393
.br

scripts/osm2pgsql-replication

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,10 @@ def get_parser():
615615
help='Database server port')
616616
group.add_argument('-p', '--prefix', metavar='PREFIX', default='planet_osm',
617617
help="Prefix for table names (default 'planet_osm')")
618-
group.add_argument('--middle-schema', metavar='MIDDLE_SCHEMA', default='public',
618+
group.add_argument('--middle-schema', metavar='SCHEMA', default=None,
619619
help='Name of the schema to store the table for the replication state in')
620+
group.add_argument('--schema', metavar='SCHEMA', default=None,
621+
help='Name of the schema for the database')
620622

621623
# Arguments for init
622624
cmd = subs.add_parser('init', parents=[default_args],
@@ -697,14 +699,16 @@ def main(prog_args=None):
697699
datefmt='%Y-%m-%d %H:%M:%S',
698700
level=max(4 - args.verbose, 1) * 10)
699701

702+
args.middle_schema = args.middle_schema or args.schema or 'public'
703+
700704
with DBConnection(args) as db:
701705
if db.table_exists(Osm2pgsqlProperties.PROP_TABLE_NAME):
702706
props = Osm2pgsqlProperties(db)
703707
else:
704708
props = LegacyProperties(db, args.prefix)
705709

706710
if not props.is_updatable:
707-
LOG.fatal(f'osm2pgsql middle table "{args.prefix}_ways" not found in database "{db.name}". '
711+
LOG.fatal(f'osm2pgsql middle table "{args.middle_schema}.{args.prefix}_ways" not found in database "{db.name}". '
708712
'Database needs to be imported in --slim mode.')
709713
return 1
710714

tests/bdd/command-line/replication.feature

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Feature: Tests for the osm2pgsql-replication script with property table
6161
Database needs to be imported in --slim mode.
6262
"""
6363

64-
Scenario: Replication can be initialised for a database in a different schema
64+
Scenario: Replication can be initialised for a database in a different schema (middle-schema)
6565
Given the database schema foobar
6666
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
6767
And the replication service at http://example.com/europe/liechtenstein-updates
@@ -78,6 +78,41 @@ Feature: Tests for the osm2pgsql-replication script with property table
7878
| replication_timestamp | 2013-08-03T19:00:02Z |
7979

8080

81+
Scenario: Replication can be initialised for a database in a different schema (schema)
82+
Given the database schema foobar
83+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
84+
And the replication service at http://example.com/europe/liechtenstein-updates
85+
When running osm2pgsql pgsql with parameters
86+
| --slim | --schema=foobar |
87+
88+
And running osm2pgsql-replication
89+
| init | --schema=foobar |
90+
91+
Then table foobar.osm2pgsql_properties contains
92+
| property | value |
93+
| replication_base_url | http://example.com/europe/liechtenstein-updates |
94+
| replication_sequence_number | 9999999 |
95+
| replication_timestamp | 2013-08-03T19:00:02Z |
96+
97+
98+
Scenario: Replication can be initialised for a database in a different schema (schema)
99+
Given the database schema foobar
100+
Given the database schema baz
101+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
102+
And the replication service at http://example.com/europe/liechtenstein-updates
103+
When running osm2pgsql pgsql with parameters
104+
| --slim | --middle-schema=foobar | --schema=baz |
105+
106+
And running osm2pgsql-replication
107+
| init | --middle-schema=foobar | --schema=baz |
108+
109+
Then table foobar.osm2pgsql_properties contains
110+
| property | value |
111+
| replication_base_url | http://example.com/europe/liechtenstein-updates |
112+
| replication_sequence_number | 9999999 |
113+
| replication_timestamp | 2013-08-03T19:00:02Z |
114+
115+
81116
Scenario: Replication initialisation will fail for a database in a different schema
82117
Given the database schema foobar
83118
Given the input file 'liechtenstein-2013-08-03.osm.pbf'

0 commit comments

Comments
 (0)