-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { readTransaction } from '../../db/index.js'; | ||
import { getUsersToMigrate } from '../../db/migration-state-queries.js'; | ||
import { delay } from '../../utils.js'; | ||
import { migrateUser } from '../migrator/user.js'; | ||
|
||
while (true) { | ||
try { | ||
const bungieMembershipIds = await readTransaction(async (client) => getUsersToMigrate(client)); | ||
for (const bungieMembershipId of bungieMembershipIds) { | ||
try { | ||
await migrateUser(bungieMembershipId); | ||
console.log(`Migrated user ${bungieMembershipId}`); | ||
} catch (e) { | ||
console.error(`Error migrating user ${bungieMembershipId}: ${e}`); | ||
} | ||
} | ||
} catch (e) { | ||
console.error(`Error getting users to migrate: ${e}`); | ||
await delay(1000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { isEmpty } from 'es-toolkit/compat'; | ||
import { doMigration } from '../../db/migration-state-queries.js'; | ||
import { pgExport } from '../../routes/export.js'; | ||
import { extractImportData, statelyImport } from '../../routes/import.js'; | ||
|
||
export async function migrateUser(bungieMembershipId: number): Promise<void> { | ||
const importToStately = async () => { | ||
// Export from Postgres | ||
const exportResponse = await pgExport(bungieMembershipId); | ||
|
||
const { settings, loadouts, itemAnnotations, triumphs, searches, itemHashTags } = | ||
extractImportData(exportResponse); | ||
|
||
const profileIds = new Set<string>(); | ||
exportResponse.loadouts.forEach((l) => profileIds.add(l.platformMembershipId)); | ||
exportResponse.tags.forEach((t) => profileIds.add(t.platformMembershipId)); | ||
exportResponse.triumphs.forEach((t) => profileIds.add(t.platformMembershipId)); | ||
|
||
if ( | ||
isEmpty(settings) && | ||
loadouts.length === 0 && | ||
itemAnnotations.length === 0 && | ||
triumphs.length === 0 && | ||
searches.length === 0 | ||
) { | ||
// Nothing to import! | ||
return; | ||
} | ||
await statelyImport( | ||
bungieMembershipId, | ||
[...profileIds], | ||
settings, | ||
loadouts, | ||
itemAnnotations, | ||
triumphs, | ||
searches, | ||
itemHashTags, | ||
false, | ||
); | ||
}; | ||
|
||
// For now let's leave the old data in Postgres as a backup | ||
await doMigration(bungieMembershipId, importToStately); | ||
} |