mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
chore: update name in one shot (#7567)
This commit is contained in:
@@ -1,25 +1,13 @@
|
||||
import { PrismaClient, User } from '@prisma/client';
|
||||
import { PrismaClient } 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],
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
await db.$executeRaw`
|
||||
UPDATE users
|
||||
SET name = split_part(email, '@', 1)
|
||||
WHERE name = 'Unnamed' AND position('@' in email) > 0;
|
||||
`;
|
||||
}
|
||||
|
||||
// revert the migration
|
||||
|
||||
Reference in New Issue
Block a user