From 4d62548fd4b3cfc323d1ee22218837fa2ec43c77 Mon Sep 17 00:00:00 2001 From: Phan Trung Thanh Date: Tue, 29 Apr 2025 16:26:58 +0200 Subject: [PATCH 1/3] update docs --- docs/how-to/migrate-to-mas.md | 45 ++++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/docs/how-to/migrate-to-mas.md b/docs/how-to/migrate-to-mas.md index 9c17a66c9..cd7b5cc5f 100644 --- a/docs/how-to/migrate-to-mas.md +++ b/docs/how-to/migrate-to-mas.md @@ -69,49 +69,44 @@ juju run synapse/leader restore-backup backup-id= ``` ## Synapse database migration -Stop all services on the new and the existing synapse charms: +Scale both synapse charms to 0 unit: ``` -juju ssh --container synapse server-mas/0 "pebble stop synapse; pebble stop synapse-mas; pebble stop stats-exporter" -juju ssh --container synapse server/0 "pebble stop synapse; pebble stop stats-exporter" +juju scale-application server-mas 0 +juju scale-application server 0 ``` -Connect the new synapse charm to the database: +Run `juju status` and save the IP address of the postgresql charm leader unit to an environment variable `DB_HOST`: ``` -juju ssh --container synapse server-mas/0 bash +juju status +export DB_HOST="" ``` -The following commands assume that you are in the `synapse` container of the `server-mas` application. +Get the password of the postgresql charm, then save the password to an environment variables `PGPASSWORD`: ``` -apt update -apt install wget postgresql-client -y -wget https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq +juju run postgresql-k8s/leader get-password +export PGPASSWORD= ``` Copy the original synapse charm database: ``` -DB_HOST=$(yq e '.database.args.host' /data/homeserver.yaml) -DB_PORT=$(yq e '.database.args.port' /data/homeserver.yaml) -DB_PASSWORD=$(yq e '.database.args.password' /data/homeserver.yaml) -DB_USER=$(yq e '.database.args.user' /data/homeserver.yaml) -PGPASSWORD=$DB_PASSWORD psql --host $DB_HOST --username $DB_USER --port $DB_PORT postgres -c 'drop database "server-mas";' -PGPASSWORD=$DB_PASSWORD psql --host $DB_HOST --username $DB_USER --port $DB_PORT postgres -c "create database \"server-mas\" with template server owner $DB_USER;" +PGPASSWORD=$PGPASSWORD psql --host $DB_HOST --username operator postgres -c 'drop database "server-mas";' +PGPASSWORD=$PGPASSWORD psql --host $DB_HOST --username operator postgres -c "create database \"server-mas\" with template server;" ``` -In case where postgres gives you an error saying "ERROR: source database "synapse" is being accessed by other users", drop all connections from the database: -First log in to the database: -``` -PGPASSWORD=$DB_PASSWORD psql --host $DB_HOST --username $DB_USER --port $DB_PORT postgres -``` +## Migrate users to MAS +### Perform user migration to MAS database -Then run this SQL query to drop all connection from the relevant database ( `` ): +The following commands assume that you are in the `synapse` container of the `server-mas` application. +> **Note**: If a proxy is present, then all commands in this section must be prefixed with `HTTP_PROXY= HTTPS_PROXY=` + +First install the necessary packages: ``` -SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity -WHERE pg_stat_activity.datname = '' AND pid <> pg_backend_pid(); +apt update +apt install wget postgresql-client -y +wget https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq ``` -## Migrate users to MAS -### Perform user migration to MAS database Run the `migrate` command with the `--dryRun` flag to check that there are no errors: ``` OAUTH2_PROVIDER_ID=$(yq e '.upstream_oauth2.providers[0].id' /mas/config.yaml) From 76a6a4a6cc97490ed7ead83979d33f5351ee410a Mon Sep 17 00:00:00 2001 From: Phan Trung Thanh Date: Tue, 29 Apr 2025 16:33:38 +0200 Subject: [PATCH 2/3] update docs --- docs/how-to/migrate-to-mas.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/how-to/migrate-to-mas.md b/docs/how-to/migrate-to-mas.md index cd7b5cc5f..c356d31c4 100644 --- a/docs/how-to/migrate-to-mas.md +++ b/docs/how-to/migrate-to-mas.md @@ -6,6 +6,8 @@ This document will cover the migration path for a synapse charm on the `1/edge` > **_NOTE:_** The existing synapse charm is deployed with the name `server`. +> **IMPORTANT**: It is extremely important that the Synapse version is the same on both the old synapse charm and the new charm to avoid any problems with database schemas. + ## Prepare the new synapse charm ### Deploy the 2/edge channel on the same model We will deploy the new synapse charm with the name `server-mas`. We will use the same configuration as the existing synapse charm. @@ -95,6 +97,14 @@ PGPASSWORD=$PGPASSWORD psql --host $DB_HOST --username operator postgres -c "cre ## Migrate users to MAS +### Update token for Draupnir +If the old synapse charm has moderation enabled, we need to modify the corresponding access token so that it does not get ignored by `syn2mas`. + +Run the following SQL command on the old synapse charm's database: +``` +PGPASSWORD=$PGPASSWORD psql --host $DB_HOST --username operator server "update access_tokens set device_id='' where token='';" +``` + ### Perform user migration to MAS database The following commands assume that you are in the `synapse` container of the `server-mas` application. From 997a3ea5f3d5e6b42cf842b77cb57008d5ae7d89 Mon Sep 17 00:00:00 2001 From: Phan Trung Thanh Date: Fri, 2 May 2025 14:54:09 +0200 Subject: [PATCH 3/3] update docs to add note about device ID --- docs/how-to/migrate-to-mas.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/how-to/migrate-to-mas.md b/docs/how-to/migrate-to-mas.md index c356d31c4..2adb20836 100644 --- a/docs/how-to/migrate-to-mas.md +++ b/docs/how-to/migrate-to-mas.md @@ -100,15 +100,17 @@ PGPASSWORD=$PGPASSWORD psql --host $DB_HOST --username operator postgres -c "cre ### Update token for Draupnir If the old synapse charm has moderation enabled, we need to modify the corresponding access token so that it does not get ignored by `syn2mas`. -Run the following SQL command on the old synapse charm's database: +Run the following SQL command on the old synapse charm's database, replacing `` with the access token that mjolnir is using, and `` with a device ID you choose ( Ideally the ID of one of your active devices ): ``` PGPASSWORD=$PGPASSWORD psql --host $DB_HOST --username operator server "update access_tokens set device_id='' where token='';" ``` +> **_NOTE:_**: The `` must exist in the `devices` table. + ### Perform user migration to MAS database The following commands assume that you are in the `synapse` container of the `server-mas` application. -> **Note**: If a proxy is present, then all commands in this section must be prefixed with `HTTP_PROXY= HTTPS_PROXY=` +> **_Note_**: If a proxy is present, then all commands in this section must be prefixed with `HTTP_PROXY= HTTPS_PROXY=` First install the necessary packages: ```