2021-10-18 11:14:12 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Test for the export-data admin command against sqlite and postgres
|
|
|
|
|
2022-04-08 15:18:54 -04:00
|
|
|
# Expects Synapse to have been already installed with `poetry install --extras postgres`.
|
|
|
|
# Expects `poetry` to be available on the `PATH`.
|
|
|
|
|
2021-10-18 11:14:12 -04:00
|
|
|
set -xe
|
2021-10-22 18:07:23 -04:00
|
|
|
cd "$(dirname "$0")/../.."
|
2021-10-18 11:14:12 -04:00
|
|
|
|
|
|
|
echo "--- Generate the signing key"
|
|
|
|
|
|
|
|
# Generate the server's signing key.
|
2022-04-08 15:18:54 -04:00
|
|
|
poetry run synapse_homeserver --generate-keys -c .ci/sqlite-config.yaml
|
2021-10-18 11:14:12 -04:00
|
|
|
|
|
|
|
echo "--- Prepare test database"
|
|
|
|
|
|
|
|
# Make sure the SQLite3 database is using the latest schema and has no pending background update.
|
2022-04-08 15:18:54 -04:00
|
|
|
poetry run update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
|
2021-10-18 11:14:12 -04:00
|
|
|
|
|
|
|
# Run the export-data command on the sqlite test database
|
2022-04-08 15:18:54 -04:00
|
|
|
poetry run python -m synapse.app.admin_cmd -c .ci/sqlite-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
|
2021-10-18 11:14:12 -04:00
|
|
|
--output-directory /tmp/export_data
|
|
|
|
|
|
|
|
# Test that the output directory exists and contains the rooms directory
|
2023-02-01 10:45:19 -05:00
|
|
|
dir_r="/tmp/export_data/rooms"
|
|
|
|
dir_u="/tmp/export_data/user_data"
|
|
|
|
if [ -d "$dir_r" ] && [ -d "$dir_u" ]; then
|
2021-10-18 11:14:12 -04:00
|
|
|
echo "Command successful, this test passes"
|
|
|
|
else
|
|
|
|
echo "No output directories found, the command fails against a sqlite database."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the PostgreSQL database.
|
2022-09-16 11:25:54 -04:00
|
|
|
psql -c "CREATE DATABASE synapse"
|
2021-10-18 11:14:12 -04:00
|
|
|
|
|
|
|
# Port the SQLite databse to postgres so we can check command works against postgres
|
|
|
|
echo "+++ Port SQLite3 databse to postgres"
|
2022-04-08 15:18:54 -04:00
|
|
|
poetry run synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
|
2021-10-18 11:14:12 -04:00
|
|
|
|
|
|
|
# Run the export-data command on postgres database
|
2022-04-08 15:18:54 -04:00
|
|
|
poetry run python -m synapse.app.admin_cmd -c .ci/postgres-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
|
2021-10-18 11:14:12 -04:00
|
|
|
--output-directory /tmp/export_data2
|
|
|
|
|
|
|
|
# Test that the output directory exists and contains the rooms directory
|
2023-02-01 10:45:19 -05:00
|
|
|
dir_r2="/tmp/export_data2/rooms"
|
|
|
|
dir_u2="/tmp/export_data2/user_data"
|
|
|
|
if [ -d "$dir_r2" ] && [ -d "$dir_u2" ]; then
|
2021-10-18 11:14:12 -04:00
|
|
|
echo "Command successful, this test passes"
|
|
|
|
else
|
|
|
|
echo "No output directories found, the command fails against a postgres database."
|
|
|
|
exit 1
|
|
|
|
fi
|