Skip to content

Commit b2f9a91

Browse files
authored
Merge branch 'main' into hughns/syn2mas-captcha
2 parents be61803 + 18f1f69 commit b2f9a91

File tree

8 files changed

+89
-36
lines changed

8 files changed

+89
-36
lines changed

tools/syn2mas/.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
22

tools/syn2mas/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# Build Node.js app
3-
FROM --platform=${BUILDPLATFORM} docker.io/library/node:18-bookworm AS builder
3+
FROM --platform=${BUILDPLATFORM} docker.io/library/node:22-bookworm AS builder
44

55
WORKDIR /syn2mas
66

@@ -10,7 +10,7 @@ RUN --network=default \
1010
npm ci
1111

1212
# Install the production dependencies for each architecture we support
13-
FROM --platform=${BUILDPLATFORM} docker.io/library/node:18-bookworm AS deps
13+
FROM --platform=${BUILDPLATFORM} docker.io/library/node:22-bookworm AS deps
1414

1515
WORKDIR /deps/arm64
1616

tools/syn2mas/package-lock.json

Lines changed: 40 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/syn2mas/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"start": "node dist/index.js"
3333
},
3434
"devDependencies": {
35-
"@tsconfig/node18": "^18.2.2",
35+
"@tsconfig/node22": "^22.0.0",
3636
"@tsconfig/strictest": "^2.0.2",
3737
"@types/command-line-args": "^5.2.2",
38-
"@types/node": "^18.18.7",
38+
"@types/node": "^22.0.0",
3939
"@typescript-eslint/eslint-plugin": "^7.3.1",
4040
"@typescript-eslint/parser": "^7.3.1",
4141
"eslint": "^8.52.0",
@@ -57,6 +57,7 @@
5757
"knex": "^3.0.1",
5858
"log4js": "^6.9.1",
5959
"pg": "^8.11.3",
60+
"pg-query-stream": "^4.6.0",
6061
"sqlite3": "^5.1.6",
6162
"ts-command-line-args": "^2.5.1",
6263
"yaml": "^2.3.3",

tools/syn2mas/src/advisor.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ export async function advisor(): Promise<void> {
9696
);
9797
if (guestUsers > 0) {
9898
error(
99-
`Synapse database contains ${guestUsers} guest users which aren't supported by MAS: https://github.com/matrix-org/matrix-authentication-service/issues/1445`,
99+
`Synapse database contains ${guestUsers} guest users which aren't supported by MAS: https://github.com/element-hq/matrix-authentication-service/issues/1445`,
100100
);
101101
}
102102
if (synapseConfig.allow_guest_access) {
103103
if (guestUsers > 0) {
104104
error(
105-
"Synapse config allows guest access which isn't supported by MAS: https://github.com/matrix-org/matrix-authentication-service/issues/1445",
105+
"Synapse config allows guest access which isn't supported by MAS: https://github.com/element-hq/matrix-authentication-service/issues/1445",
106106
);
107107
} else {
108108
error(
109-
"Synapse config allows guest access which isn't supported by MAS, but no guest users were found in the database so the option could be disabled: https://github.com/matrix-org/matrix-authentication-service/issues/1445",
109+
"Synapse config allows guest access which isn't supported by MAS, but no guest users were found in the database so the option could be disabled: https://github.com/element-hq/matrix-authentication-service/issues/1445",
110110
);
111111
}
112112
}
@@ -140,7 +140,7 @@ export async function advisor(): Promise<void> {
140140
);
141141
if (usersWithoutEmailAddress > 0) {
142142
warn(
143-
`Synapse database contains ${usersWithoutEmailAddress} users without a verified email address who will need to verify their email address before they can login after migration: https://github.com/matrix-org/matrix-authentication-service/issues/1505`,
143+
`Synapse database contains ${usersWithoutEmailAddress} users without a verified email address who will need to verify their email address before they can login after migration: https://github.com/element-hq/matrix-authentication-service/issues/1505`,
144144
);
145145
}
146146

tools/syn2mas/src/migrate.mts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,7 @@ export async function migrate(): Promise<void> {
192192
);
193193
}
194194

195-
// Get all Synapse users, except appservice owned users who don't need to be migrated
196-
const synapseUsers = await synapse
197-
.select("*")
198-
.from<SUser>("users")
199-
.whereNull("appservice_id");
200-
log.info(`Found ${synapseUsers.length} users in Synapse`);
201-
for (const user of synapseUsers) {
195+
async function migrateUser(user: SUser): Promise<void> {
202196
const localpart = user.name.split(":")[0].substring(1);
203197
log.info(`Processing user ${user.name} as ${localpart}`);
204198

@@ -430,10 +424,43 @@ export async function migrate(): Promise<void> {
430424
}
431425
}
432426
}
427+
428+
// this is a workaround to get the list of columns that we care about from the SUser type
429+
const SUserColumns: Record<keyof SUser, undefined> = {
430+
name: undefined,
431+
password_hash: undefined,
432+
admin: undefined,
433+
is_guest: undefined,
434+
deactivated: undefined,
435+
creation_ts: undefined,
436+
appservice_id: undefined,
437+
};
438+
439+
// Get all Synapse users, except appservice owned users who don't need to be migrated
440+
const synapseUserQuery = synapse
441+
.select(Object.keys(SUserColumns) as (keyof SUser)[])
442+
.from<SUser>("users")
443+
.whereNull("appservice_id");
444+
445+
let synapseUsers = 0;
446+
if (synapseConfig.database.name === "sqlite3") {
447+
// SQLite doesn't support streaming
448+
const synapseUserRows = (await synapseUserQuery) as unknown as SUser[];
449+
for (const user of synapseUserRows) {
450+
synapseUsers += 1;
451+
await migrateUser(user);
452+
}
453+
} else {
454+
// Stream users from the database
455+
const synapseUserStream = synapseUserQuery.stream();
456+
for await (const user of synapseUserStream) {
457+
synapseUsers += 1;
458+
await migrateUser(user as unknown as SUser);
459+
}
460+
}
461+
433462
log.info(
434-
`Completed migration ${args.dryRun ? "dry-run " : ""}of ${
435-
synapseUsers.length
436-
} users with ${fatals} fatals and ${warnings.length} warnings:`,
463+
`Completed migration ${args.dryRun ? "dry-run " : ""}of ${synapseUsers} users with ${fatals} fatals and ${warnings.length} warnings:`,
437464
);
438465
warnings.forEach((w) => log.warn(w));
439466
if (fatals > 0) {

tools/syn2mas/tsconfig.eslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": [
33
"@tsconfig/strictest/tsconfig.json",
4-
"@tsconfig/node18/tsconfig.json",
4+
"@tsconfig/node22/tsconfig.json",
55
],
66
"compilerOptions": {
77
"noEmit": true,

tools/syn2mas/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": [
33
"@tsconfig/strictest/tsconfig.json",
4-
"@tsconfig/node18/tsconfig.json"
4+
"@tsconfig/node22/tsconfig.json"
55
],
66
"compilerOptions": {
77
"outDir": "dist",

0 commit comments

Comments
 (0)