Skip to content

Commit 7d7a970

Browse files
authored
Merge pull request #2260 from lonvia/properly-propagate-schema-on-update
Properly forward schema parameters from replication script
2 parents 7609e0e + 9b16c43 commit 7d7a970

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

scripts/osm2pgsql-replication

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class DBError(Exception):
111111

112112
class DBConnection:
113113

114-
def __init__(self, args):
115-
self.schema = args.middle_schema
114+
def __init__(self, schema, args):
115+
self.schema = schema
116116

117117
# If dbname looks like a conninfo string use it as such
118118
if args.database and any(part in args.database for part in ['=', '://']):
@@ -535,8 +535,10 @@ def update(props, args):
535535

536536
osm2pgsql = [args.osm2pgsql_cmd, '--append', '--slim', '--prefix', args.prefix]
537537
osm2pgsql.extend(args.extra_params)
538-
if args.middle_schema != 'public':
538+
if args.middle_schema:
539539
osm2pgsql.extend(('--middle-schema', args.middle_schema))
540+
if args.schema:
541+
osm2pgsql.extend(('--schema', args.schema))
540542
if args.database:
541543
osm2pgsql.extend(('-d', args.database))
542544
if args.username:
@@ -717,16 +719,16 @@ def main(prog_args=None):
717719
datefmt='%Y-%m-%d %H:%M:%S',
718720
level=max(4 - args.verbose, 1) * 10)
719721

720-
args.middle_schema = args.middle_schema or args.schema or 'public'
722+
prop_table_schema = args.middle_schema or args.schema or 'public'
721723

722-
with DBConnection(args) as db:
724+
with DBConnection(prop_table_schema, args) as db:
723725
if db.table_exists(Osm2pgsqlProperties.PROP_TABLE_NAME):
724726
props = Osm2pgsqlProperties(db)
725727
else:
726728
props = LegacyProperties(db, args.prefix)
727729

728730
if not props.is_updatable:
729-
LOG.fatal(f'osm2pgsql middle table "{args.middle_schema}.{args.prefix}_ways" not found in database "{db.name}". '
731+
LOG.fatal(f'osm2pgsql middle table "{prop_table_schema}.{args.prefix}_ways" not found in database "{db.name}". '
730732
'Database needs to be imported in --slim mode.')
731733
return 1
732734

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Feature: Tests for the osm2pgsql-replication script with schemas
2+
3+
Scenario: Replication updates work on database with schema
4+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
5+
And the database schema foobar
6+
And the replication service at http://example.com/europe/liechtenstein-updates
7+
| sequence | timestamp |
8+
| 9999999 | 2013-08-01T01:00:02Z |
9+
| 10000000 | 2013-09-01T01:00:00Z |
10+
| 10000001 | 2013-10-01T01:00:00Z |
11+
When running osm2pgsql pgsql with parameters
12+
| --slim | --schema | foobar |
13+
And running osm2pgsql-replication
14+
| init | --schema | foobar |
15+
And running osm2pgsql-replication
16+
| update | --schema | foobar |
17+
18+
Then table foobar.osm2pgsql_properties contains
19+
| property | value |
20+
| replication_base_url | http://example.com/europe/liechtenstein-updates |
21+
| replication_sequence_number | 10000001 |
22+
| replication_timestamp | 2013-10-01T01:00:00Z |
23+
24+
25+
Scenario: Replication updates work on database with different middle schema
26+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
27+
And the database schema foobar
28+
And the replication service at http://example.com/europe/liechtenstein-updates
29+
| sequence | timestamp |
30+
| 9999999 | 2013-08-01T01:00:02Z |
31+
| 10000000 | 2013-09-01T01:00:00Z |
32+
| 10000001 | 2013-10-01T01:00:00Z |
33+
When running osm2pgsql pgsql with parameters
34+
| --slim | --middle-schema | foobar |
35+
And running osm2pgsql-replication
36+
| init | --middle-schema | foobar |
37+
And running osm2pgsql-replication
38+
| update | --middle-schema | foobar |
39+
40+
Then table foobar.osm2pgsql_properties contains
41+
| property | value |
42+
| replication_base_url | http://example.com/europe/liechtenstein-updates |
43+
| replication_sequence_number | 10000001 |
44+
| replication_timestamp | 2013-10-01T01:00:00Z |
45+
46+
47+
Scenario: Replication updates work on database with middle schema different from schema
48+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
49+
And the database schema foobar
50+
And the database schema baz
51+
And the replication service at http://example.com/europe/liechtenstein-updates
52+
| sequence | timestamp |
53+
| 9999999 | 2013-08-01T01:00:02Z |
54+
| 10000000 | 2013-09-01T01:00:00Z |
55+
| 10000001 | 2013-10-01T01:00:00Z |
56+
When running osm2pgsql pgsql with parameters
57+
| --slim | --middle-schema | foobar | --schema | baz |
58+
And running osm2pgsql-replication
59+
| init | --middle-schema | foobar | --schema | baz |
60+
And running osm2pgsql-replication
61+
| update | --middle-schema | foobar | --schema | baz |
62+
63+
Then table foobar.osm2pgsql_properties contains
64+
| property | value |
65+
| replication_base_url | http://example.com/europe/liechtenstein-updates |
66+
| replication_sequence_number | 10000001 |
67+
| replication_timestamp | 2013-10-01T01:00:00Z |
68+

0 commit comments

Comments
 (0)