refactor: update migration

This commit is contained in:
Mauricio Siu 2025-02-13 00:57:22 -06:00
parent 0d525398a8
commit d1f72a2e20
2 changed files with 35 additions and 0 deletions

View File

@ -150,6 +150,32 @@ inserted_members AS (
JOIN admin a ON u."adminId" = a."adminId"
JOIN auth ON auth.id = u."authId"
RETURNING *
),
inserted_member_accounts AS (
-- Insertar cuentas para los usuarios miembros
INSERT INTO account (
id,
"account_id",
"provider_id",
"user_id",
password,
"is2FAEnabled",
"created_at",
"updated_at"
)
SELECT
gen_random_uuid(),
gen_random_uuid(),
'credentials',
u."userId",
auth.password,
COALESCE(auth."is2FAEnabled", false),
NOW(),
NOW()
FROM "user" u
JOIN admin a ON u."adminId" = a."adminId"
JOIN auth ON auth.id = u."authId"
RETURNING *
)
-- Insertar miembros en las organizaciones
INSERT INTO member (

View File

@ -100,6 +100,15 @@ await db
.returning()
.then((userTemp) => userTemp[0]);
await db.insert(schema.account).values({
providerId: "credentials",
userId: member?.userId || "",
password: member.auth.password,
is2FAEnabled: member.auth.is2FAEnabled || false,
createdAt: new Date(member.auth.createdAt) || new Date(),
updatedAt: new Date(member.auth.createdAt) || new Date(),
});
await db.insert(schema.member).values({
organizationId: organization?.id || "",
userId: userTemp?.id || "",