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
1215cd " $( dirname " $0 " ) /../.."
1316
1417echo " --- Generate the signing key"
15-
16- # Generate the server's signing key.
1718poetry run synapse_homeserver --generate-keys -c .ci/sqlite-config.yaml
1819
1920echo " --- 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.
2222poetry 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
2727echo " +++ 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
4545poetry 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
5252echo " +++ Run synapse_port_db against empty database"
5353poetry 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
0 commit comments