wip: test

This commit is contained in:
David Nguyen
2025-01-05 15:44:16 +11:00
parent 866b036484
commit 071ce70292
20 changed files with 903 additions and 349 deletions

View File

@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "secondaryId" TEXT;
-- Set all null secondaryId fields to a uuid
UPDATE "User" SET "secondaryId" = gen_random_uuid()::text WHERE "secondaryId" IS NULL;
-- Restrict the User to required
ALTER TABLE "User" ALTER COLUMN "secondaryId" SET NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX "User_secondaryId_key" ON "User"("secondaryId");

View File

@ -0,0 +1,36 @@
/*
Warnings:
- Added the required column `updatedAt` to the `Account` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `Session` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Account" ADD COLUMN "accessTokenExpiresAt" TIMESTAMP(3),
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "password" TEXT,
ADD COLUMN "refreshTokenExpiresAt" TIMESTAMP(3),
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL,
ALTER COLUMN "type" SET DEFAULT 'legacy';
-- AlterTable
ALTER TABLE "Session" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "ipAddress" TEXT,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL,
ADD COLUMN "userAgent" TEXT;
-- AlterTable
ALTER TABLE "User" ADD COLUMN "image" TEXT,
ADD COLUMN "isEmailVerified" BOOLEAN NOT NULL DEFAULT false;
-- CreateTable
CREATE TABLE "verification" (
"id" TEXT NOT NULL,
"identifier" TEXT NOT NULL,
"value" TEXT NOT NULL,
"expiresAt" TIMESTAMP(3) NOT NULL,
"createdAt" TIMESTAMP(3),
"updatedAt" TIMESTAMP(3),
CONSTRAINT "verification_pkey" PRIMARY KEY ("id")
);

View File

@ -0,0 +1,28 @@
-- Migrate DOCUMENSO users to have proper Account records
DO $$
BEGIN
INSERT INTO "Account" (
"id",
"userId",
"type",
"provider",
"providerAccountId",
"password",
"createdAt",
"updatedAt"
)
SELECT
gen_random_uuid()::text,
u.id,
'legacy',
'credential',
u.email,
u.password,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
FROM "User" u
LEFT JOIN "Account" a ON a."userId" = u.id AND a."provider" = 'documenso'
WHERE
u."identityProvider" = 'DOCUMENSO'
AND a.id IS NULL;
END $$;

View File

@ -0,0 +1,32 @@
-- CreateTable
CREATE TABLE "TwoFactor" (
"id" TEXT NOT NULL,
"secret" TEXT NOT NULL,
"backupCodes" TEXT NOT NULL,
"userId" INTEGER NOT NULL,
CONSTRAINT "TwoFactor_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "TwoFactor" ADD CONSTRAINT "TwoFactor_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
DO $$
BEGIN
-- Then migrate two factor data
INSERT INTO "TwoFactor" (
"secret",
"backupCodes",
"userId"
)
SELECT
u."twoFactorSecret",
COALESCE(u."twoFactorBackupCodes", ''),
u.id
FROM "User" u
LEFT JOIN "TwoFactor" tf ON tf."userId" = u.id
WHERE
u."twoFactorSecret" IS NOT NULL
AND u."twoFactorEnabled" = true
AND tf.id IS NULL;
END $$;