Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 642c4b2

Browse files
author
David Robertson
authored
Compare ported to unported PG schemas in portdb test job (#13808)
1 parent 5e84461 commit 642c4b2

File tree

5 files changed

+50
-47
lines changed

5 files changed

+50
-47
lines changed

.ci/scripts/postgres_exec.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

.ci/scripts/test_export_data_command.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ else
3232
fi
3333

3434
# Create the PostgreSQL database.
35-
poetry run .ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
35+
psql -c "CREATE DATABASE synapse"
3636

3737
# Port the SQLite databse to postgres so we can check command works against postgres
3838
echo "+++ Port SQLite3 databse to postgres"

.ci/scripts/test_synapse_port_db.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
#
33
# Test script for 'synapse_port_db'.
44
# - configures synapse and a postgres server.
5-
# - runs the port script on a prepopulated test sqlite db
6-
# - also runs it against an new sqlite db
5+
# - runs the port script on a prepopulated test sqlite db. Checks that the
6+
# return code is zero.
7+
# - reruns the port script on the same sqlite db, targetting the same postgres db.
8+
# Checks that the return code is zero.
9+
# - runs the port script against a new sqlite db. Checks the return code is zero.
710
#
811
# Expects Synapse to have been already installed with `poetry install --extras postgres`.
912
# Expects `poetry` to be available on the `PATH`.
1013

11-
set -xe
14+
set -xe -o pipefail
1215
cd "$(dirname "$0")/../.."
1316

1417
echo "--- Generate the signing key"
15-
16-
# Generate the server's signing key.
1718
poetry run synapse_homeserver --generate-keys -c .ci/sqlite-config.yaml
1819

1920
echo "--- Prepare test database"
20-
21-
# Make sure the SQLite3 database is using the latest schema and has no pending background update.
21+
# Make sure the SQLite3 database is using the latest schema and has no pending background updates.
2222
poetry run update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
2323

2424
# Create the PostgreSQL database.
25-
poetry run .ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
25+
psql -c "CREATE DATABASE synapse"
2626

2727
echo "+++ Run synapse_port_db against test database"
2828
# TODO: this invocation of synapse_port_db (and others below) used to be prepended with `coverage run`,
@@ -45,9 +45,23 @@ rm .ci/test_db.db
4545
poetry run update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
4646

4747
# re-create the PostgreSQL database.
48-
poetry run .ci/scripts/postgres_exec.py \
49-
"DROP DATABASE synapse" \
50-
"CREATE DATABASE synapse"
48+
psql \
49+
-c "DROP DATABASE synapse" \
50+
-c "CREATE DATABASE synapse"
5151

5252
echo "+++ Run synapse_port_db against empty database"
5353
poetry run synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
54+
55+
echo "--- Create a brand new postgres database from schema"
56+
cp .ci/postgres-config.yaml .ci/postgres-config-unported.yaml
57+
sed -i -e 's/database: synapse/database: synapse_unported/' .ci/postgres-config-unported.yaml
58+
psql -c "CREATE DATABASE synapse_unported"
59+
poetry run update_synapse_database --database-config .ci/postgres-config-unported.yaml --run-background-updates
60+
61+
echo "+++ Comparing ported schema with unported schema"
62+
# Ignore the tables that portdb creates. (Should it tidy them up when the porting is completed?)
63+
psql synapse -c "DROP TABLE port_from_sqlite3;"
64+
pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner synapse_unported > unported.sql
65+
pg_dump --format=plain --schema-only --no-tablespaces --no-acl --no-owner synapse > ported.sql
66+
# By default, `diff` returns zero if there are no changes and nonzero otherwise
67+
diff -u unported.sql ported.sql | tee schema_diff

.github/workflows/tests.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,22 @@ jobs:
362362
363363
steps:
364364
- uses: actions/checkout@v2
365-
- run: sudo apt-get -qq install xmlsec1
365+
- run: sudo apt-get -qq install xmlsec1 postgresql-client
366366
- uses: matrix-org/setup-python-poetry@v1
367367
with:
368368
extras: "postgres"
369369
- run: .ci/scripts/test_export_data_command.sh
370+
env:
371+
PGHOST: localhost
372+
PGUSER: postgres
373+
PGPASSWORD: postgres
374+
PGDATABASE: postgres
375+
370376

371377
portdb:
372378
if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
373379
needs: linting-done
374380
runs-on: ubuntu-latest
375-
env:
376-
TOP: ${{ github.workspace }}
377381
strategy:
378382
matrix:
379383
include:
@@ -399,12 +403,27 @@ jobs:
399403
400404
steps:
401405
- uses: actions/checkout@v2
402-
- run: sudo apt-get -qq install xmlsec1
406+
- run: sudo apt-get -qq install xmlsec1 postgresql-client
403407
- uses: matrix-org/setup-python-poetry@v1
404408
with:
405409
python-version: ${{ matrix.python-version }}
406410
extras: "postgres"
407411
- run: .ci/scripts/test_synapse_port_db.sh
412+
id: run_tester_script
413+
env:
414+
PGHOST: localhost
415+
PGUSER: postgres
416+
PGPASSWORD: postgres
417+
PGDATABASE: postgres
418+
- name: "Upload schema differences"
419+
uses: actions/upload-artifact@v3
420+
if: ${{ failure() && !cancelled() && steps.run_tester_script.outcome == 'failure' }}
421+
with:
422+
name: Schema dumps
423+
path: |
424+
unported.sql
425+
ported.sql
426+
schema_diff
408427
409428
complement:
410429
if: "${{ !failure() && !cancelled() }}"

changelog.d/13808.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check that portdb generates the same postgres schema as that in the source tree.

0 commit comments

Comments
 (0)