Skip to content

Commit c42e200

Browse files
authored
Merge pull request #1901 from lonvia/schema-in-replication-script
Correctly apply middle-schema parameter in replication script
2 parents 1359e2e + 943c427 commit c42e200

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

.github/workflows/test-install.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ jobs:
66
ubuntu-test-install:
77
runs-on: ubuntu-20.04
88

9+
strategy:
10+
matrix:
11+
flavour: [public, middle_schema]
12+
include:
13+
- flavour: public
14+
options: ""
15+
schema: ""
16+
- flavour: middle_schema
17+
options: "--middle-schema=myschema"
18+
schema: "myschema"
19+
920
env:
1021
LUA_VERSION: 5.3
1122
POSTGRESQL_VERSION: 12
@@ -75,8 +86,16 @@ jobs:
7586
sudo systemctl start postgresql
7687
sudo -u postgres createuser runner
7788
sudo -u postgres createdb -O runner o2ptest
78-
sudo -u postgres psql o2ptest -c "CREATE EXTENSION postgis;"
79-
sudo -u postgres psql o2ptest -c "CREATE EXTENSION hstore;"
89+
sudo -u postgres psql o2ptest -c "CREATE EXTENSION postgis"
90+
sudo -u postgres psql o2ptest -c "CREATE EXTENSION hstore"
91+
92+
- name: Set up schema
93+
run: |
94+
sudo -u postgres psql o2ptest -c "CREATE SCHEMA $SCHEMANAME"
95+
sudo -u postgres psql o2ptest -c "GRANT ALL ON SCHEMA $SCHEMANAME TO runner"
96+
if: ${{ matrix.schema }}
97+
env:
98+
SCHEMANAME: ${{ matrix.schema }}
8099

81100
- name: Remove repository
82101
# Remove contents of workspace to be sure the install runs independently
@@ -92,15 +111,18 @@ jobs:
92111
run: wget --quiet $OSMURL
93112
working-directory: /tmp
94113

95-
- name: Test run of osm2pgsql
96-
run: $PREFIX/bin/osm2pgsql -d o2ptest --slim $OSMFILE
114+
- name: Test run of osm2pgsql (no schema)
115+
run: $PREFIX/bin/osm2pgsql $EXTRAOPTS -d o2ptest --slim $OSMFILE
97116
working-directory: /tmp
117+
env:
118+
EXTRAOPTS: ${{ matrix.options }}
98119

99-
- name: Test run osm2pgsql-replication
120+
- name: Test run osm2pgsql-replication (no schema)
100121
run: |
101-
$PREFIX/bin/osm2pgsql-replication init -v -d o2ptest
102-
$PREFIX/bin/osm2pgsql-replication status -v -d o2ptest
103-
$PREFIX/bin/osm2pgsql-replication update -v -d o2ptest --once --max-diff-size=1
104-
$PREFIX/bin/osm2pgsql-replication status -v -d o2ptest --json
122+
$PREFIX/bin/osm2pgsql-replication init $EXTRAOPTS -v -d o2ptest
123+
$PREFIX/bin/osm2pgsql-replication status $EXTRAOPTS -v -d o2ptest
124+
$PREFIX/bin/osm2pgsql-replication update $EXTRAOPTS -v -d o2ptest --once --max-diff-size=1
125+
$PREFIX/bin/osm2pgsql-replication status $EXTRAOPTS -v -d o2ptest --json
105126
working-directory: /tmp
106-
127+
env:
128+
EXTRAOPTS: ${{ matrix.options }}

scripts/osm2pgsql-replication

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ def table_exists(conn, table_name, schema_name=None):
9595
return cur.rowcount > 0
9696

9797

98-
def compute_database_date(conn, prefix):
98+
def compute_database_date(conn, schema, prefix):
9999
""" Determine the date of the database from the newest object in the
100100
database.
101101
"""
102102
# First, find the way with the highest ID in the database
103103
# Using nodes would be more reliable but those are not cached by osm2pgsql.
104104
with conn.cursor() as cur:
105-
table = sql.Identifier(f'{prefix}_ways')
105+
table = sql.Identifier(schema, f'{prefix}_ways')
106106
cur.execute(sql.SQL("SELECT max(id) FROM {}").format(table))
107107
osmid = cur.fetchone()[0] if cur.rowcount == 1 else None
108108

@@ -290,7 +290,7 @@ def init(conn, args):
290290
this with the `--server` parameter.
291291
"""
292292
if args.osm_file is None:
293-
date = compute_database_date(conn, args.prefix)
293+
date = compute_database_date(conn, args.middle_schema, args.prefix)
294294
if date is None:
295295
return 1
296296

@@ -383,6 +383,8 @@ def update(conn, args):
383383

384384
osm2pgsql = [args.osm2pgsql_cmd, '--append', '--slim', '--prefix', args.prefix]
385385
osm2pgsql.extend(args.extra_params)
386+
if args.middle_schema != 'public':
387+
osm2pgsql.extend(('--middle-schema', args.middle_schema))
386388
if args.database:
387389
osm2pgsql.extend(('-d', args.database))
388390
if args.username:

0 commit comments

Comments
 (0)