chore: refresh unnamed user (#7544)

This commit is contained in:
darkskygit
2024-07-19 04:01:39 +00:00
parent 90c00b6db9
commit 145872b9f4
3 changed files with 27 additions and 4 deletions

View File

@@ -9,9 +9,6 @@ export class UnamedAccount1703756315970 {
const users = await db.$queryRaw<
User[]
>`SELECT * FROM users WHERE name ~ E'^[\\s\\u2000-\\u200F]*$';`;
console.log(
`renaming ${users.map(({ email }) => email).join('|')} users`
);
await Promise.all(
users.map(({ id, email }) =>

View File

@@ -0,0 +1,27 @@
import { PrismaClient, User } from '@prisma/client';
export class RefreshUnnamedUser1721299086340 {
// do the migration
static async up(db: PrismaClient) {
await db.$transaction(async tx => {
// only find users with unnamed names
const users = await db.$queryRaw<
User[]
>`SELECT * FROM users WHERE name = 'Unnamed';`;
await Promise.all(
users.map(({ id, email }) =>
tx.user.update({
where: { id },
data: {
name: email.split('@')[0],
},
})
)
);
});
}
// revert the migration
static async down(_db: PrismaClient) {}
}