mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +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 {
|
export class RefreshUnnamedUser1721299086340 {
|
||||||
// do the migration
|
// do the migration
|
||||||
static async up(db: PrismaClient) {
|
static async up(db: PrismaClient) {
|
||||||
await db.$transaction(async tx => {
|
await db.$executeRaw`
|
||||||
// only find users with unnamed names
|
UPDATE users
|
||||||
const users = await db.$queryRaw<
|
SET name = split_part(email, '@', 1)
|
||||||
User[]
|
WHERE name = 'Unnamed' AND position('@' in email) > 0;
|
||||||
>`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
|
// revert the migration
|
||||||
|
|||||||
Reference in New Issue
Block a user