fix(db): switch blockId and groupId on old answers
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
-- Update old answers
|
||||
UPDATE "Answer" a
|
||||
SET "blockId" = a."groupId",
|
||||
"groupId" = a."blockId"
|
||||
WHERE "createdAt" < '2022-06-10 22:00:00 UTC'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM "Answer"
|
||||
WHERE "resultId" = a."resultId"
|
||||
AND "blockId" = a."groupId"
|
||||
AND "groupId" = a."blockId"
|
||||
);
|
@ -24,7 +24,11 @@ const prisma = new PrismaClient({
|
||||
require('dotenv').config({
|
||||
path: path.join(
|
||||
__dirname,
|
||||
process.env.NODE_ENV === 'production' ? '.env.production' : '.env.local'
|
||||
process.env.NODE_ENV === 'production'
|
||||
? '.env.production'
|
||||
: process.env.NODE_ENV === 'staging'
|
||||
? '.env.staging'
|
||||
: '.env.local'
|
||||
),
|
||||
})
|
||||
|
||||
@ -34,6 +38,12 @@ const main = async () => {
|
||||
console.log('Params: ' + e.params)
|
||||
console.log('Duration: ' + e.duration + 'ms')
|
||||
})
|
||||
const date = new Date()
|
||||
const lastMonth = new Date(date.getFullYear(), date.getMonth() - 1, 10)
|
||||
const answers = await prisma.answer.findMany({
|
||||
where: { createdAt: { lt: lastMonth } },
|
||||
take: 100,
|
||||
})
|
||||
}
|
||||
|
||||
main().then()
|
||||
|
@ -6,6 +6,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start:local": "ts-node index.ts",
|
||||
"start:staging": "NODE_ENV=staging ts-node index.ts",
|
||||
"start:prod": "NODE_ENV=production ts-node index.ts",
|
||||
"start:workspaces:migration": "ts-node workspaceMigration.ts",
|
||||
"start:workspaces:migration:recover": "ts-node workspaceMigrationRecover.ts"
|
||||
|
Reference in New Issue
Block a user