-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into darksky/mutate-db-with-transaction
- Loading branch information
Showing
147 changed files
with
1,206 additions
and
986 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
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
39 changes: 39 additions & 0 deletions
39
packages/backend/server/src/data/migrations/1710319359062-oauth.ts
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,39 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
import { loop } from './utils/loop'; | ||
|
||
export class Oauth1710319359062 { | ||
// do the migration | ||
static async up(db: PrismaClient) { | ||
await loop(async (skip, take) => { | ||
const oldRecords = await db.deprecatedNextAuthAccount.findMany({ | ||
skip, | ||
take, | ||
orderBy: { | ||
providerAccountId: 'asc', | ||
}, | ||
}); | ||
|
||
await db.connectedAccount.createMany({ | ||
data: oldRecords.map(record => ({ | ||
userId: record.userId, | ||
provider: record.provider, | ||
scope: record.scope, | ||
providerAccountId: record.providerAccountId, | ||
accessToken: record.access_token, | ||
refreshToken: record.refresh_token, | ||
expiresAt: record.expires_at | ||
? new Date(record.expires_at * 1000) | ||
: null, | ||
})), | ||
}); | ||
|
||
return oldRecords.length; | ||
}, 10); | ||
} | ||
|
||
// revert the migration | ||
static async down(db: PrismaClient) { | ||
await db.connectedAccount.deleteMany({}); | ||
} | ||
} |
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,13 @@ | ||
export async function loop( | ||
batchFn: (skip: number, take: number) => Promise<number>, | ||
chunkSize: number = 100 | ||
) { | ||
let turn = 0; | ||
let last = chunkSize; | ||
|
||
while (last === chunkSize) { | ||
last = await batchFn(chunkSize * turn, chunkSize); | ||
|
||
turn++; | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.