@@ -192,13 +192,7 @@ export async function migrate(): Promise<void> {
192
192
) ;
193
193
}
194
194
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 > {
202
196
const localpart = user . name . split ( ":" ) [ 0 ] . substring ( 1 ) ;
203
197
log . info ( `Processing user ${ user . name } as ${ localpart } ` ) ;
204
198
@@ -430,10 +424,43 @@ export async function migrate(): Promise<void> {
430
424
}
431
425
}
432
426
}
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
+
433
462
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:` ,
437
464
) ;
438
465
warnings . forEach ( ( w ) => log . warn ( w ) ) ;
439
466
if ( fatals > 0 ) {
0 commit comments