wip: what if user ids were strings instead of numbers

This commit is contained in:
Mythie
2025-01-03 16:23:35 +11:00
parent 18ca0cf3d6
commit b685190b1a
134 changed files with 775 additions and 246 deletions

View File

@ -0,0 +1,94 @@
-- !: This needs to run first
-- AlterTable
ALTER TABLE "User" ADD COLUMN "secondaryId" TEXT;
-- Set all null secondaryId users to a uuid
UPDATE "User" SET "secondaryId" = gen_random_uuid()::text WHERE "secondaryId" IS NULL;
-- Restrict the secondaryId to required
ALTER TABLE "User" ALTER COLUMN "secondaryId" SET NOT NULL;
-- Now lets update all the tables that reference the user table to use the secondaryId
-- AlterTable
ALTER TABLE "Account" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Account" a SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = a."userId");
-- AlterTable
ALTER TABLE "ApiToken" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "ApiToken" a SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = a."userId");
-- AlterTable
ALTER TABLE "Document" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Document" d SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = d."userId");
-- AlterTable
ALTER TABLE "Passkey" ADD COLUMN "secondaryUserId" TEXT NOT NULL;
UPDATE "Passkey" p SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = p."userId");
-- AlterTable
ALTER TABLE "PasswordResetToken" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "PasswordResetToken" p SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = p."userId");
-- AlterTable
ALTER TABLE "Session" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Session" s SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = s."userId");
-- AlterTable
ALTER TABLE "SiteSettings" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "SiteSettings" s SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = s."lastModifiedByUserId");
-- AlterTable
ALTER TABLE "Subscription" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Subscription" s SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = s."userId");
-- AlterTable
ALTER TABLE "Team" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Team" t SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = t."ownerUserId");
-- AlterTable
ALTER TABLE "TeamMember" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "TeamMember" tm SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = tm."userId");
-- AlterTable
ALTER TABLE "TeamPending" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "TeamPending" tp SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = tp."ownerUserId");
-- AlterTable
ALTER TABLE "Template" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Template" t SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = t."userId");
-- AlterTable
ALTER TABLE "UserProfile" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "UserProfile" up SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = up."userId");
-- AlterTable
ALTER TABLE "UserSecurityAuditLog" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "UserSecurityAuditLog" usal SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = usal."userId");
-- AlterTable
ALTER TABLE "VerificationToken" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "VerificationToken" vt SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = vt."userId");
-- AlterTable
ALTER TABLE "Webhook" ADD COLUMN "secondaryUserId" TEXT;
UPDATE "Webhook" w SET "secondaryUserId" = (SELECT "secondaryId" FROM "User" u WHERE u."id" = w."userId");
-- CreateIndex
CREATE UNIQUE INDEX "User_secondaryId_key" ON "User"("secondaryId");

View File

@ -0,0 +1,199 @@
/*
Warnings:
- You are about to drop the column `secondaryUserId` on the `Account` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `ApiToken` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Document` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Passkey` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `PasswordResetToken` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Session` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `SiteSettings` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Subscription` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Team` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `TeamMember` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `TeamPending` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Template` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `UserProfile` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `UserSecurityAuditLog` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `VerificationToken` table. All the data in the column will be lost.
- You are about to drop the column `secondaryUserId` on the `Webhook` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey";
-- DropForeignKey
ALTER TABLE "ApiToken" DROP CONSTRAINT "ApiToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "Document" DROP CONSTRAINT "Document_userId_fkey";
-- DropForeignKey
ALTER TABLE "Passkey" DROP CONSTRAINT "Passkey_userId_fkey";
-- DropForeignKey
ALTER TABLE "PasswordResetToken" DROP CONSTRAINT "PasswordResetToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey";
-- DropForeignKey
ALTER TABLE "SiteSettings" DROP CONSTRAINT "SiteSettings_lastModifiedByUserId_fkey";
-- DropForeignKey
ALTER TABLE "Subscription" DROP CONSTRAINT "Subscription_userId_fkey";
-- DropForeignKey
ALTER TABLE "Team" DROP CONSTRAINT "Team_ownerUserId_fkey";
-- DropForeignKey
ALTER TABLE "TeamMember" DROP CONSTRAINT "TeamMember_userId_fkey";
-- DropForeignKey
ALTER TABLE "TeamPending" DROP CONSTRAINT "TeamPending_ownerUserId_fkey";
-- DropForeignKey
ALTER TABLE "Template" DROP CONSTRAINT "Template_userId_fkey";
-- DropForeignKey
ALTER TABLE "UserProfile" DROP CONSTRAINT "UserProfile_userId_fkey";
-- DropForeignKey
ALTER TABLE "UserSecurityAuditLog" DROP CONSTRAINT "UserSecurityAuditLog_userId_fkey";
-- DropForeignKey
ALTER TABLE "VerificationToken" DROP CONSTRAINT "VerificationToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_userId_fkey";
-- AlterTable
ALTER TABLE "Account" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Account" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Account" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "ApiToken" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "ApiToken" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "ApiToken" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "Document" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Document" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Document" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "Passkey" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Passkey" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Passkey" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "PasswordResetToken" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "PasswordResetToken" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "PasswordResetToken" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "Session" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Session" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Session" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "SiteSettings" RENAME COLUMN "lastModifiedByUserId" TO "lastModifiedByUserId_old";
ALTER TABLE "SiteSettings" RENAME COLUMN "secondaryUserId" TO "lastModifiedByUserId";
ALTER TABLE "SiteSettings" DROP COLUMN "lastModifiedByUserId_old";
-- AlterTable
ALTER TABLE "Subscription" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Subscription" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Subscription" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "Team" RENAME COLUMN "ownerUserId" TO "ownerUserId_old";
ALTER TABLE "Team" RENAME COLUMN "secondaryUserId" TO "ownerUserId";
ALTER TABLE "Team" DROP COLUMN "ownerUserId_old";
-- AlterTable
ALTER TABLE "TeamMember" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "TeamMember" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "TeamMember" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "TeamPending" RENAME COLUMN "ownerUserId" TO "ownerUserId_old";
ALTER TABLE "TeamPending" RENAME COLUMN "secondaryUserId" TO "ownerUserId";
ALTER TABLE "TeamPending" DROP COLUMN "ownerUserId_old";
-- AlterTable
ALTER TABLE "Template" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Template" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Template" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "UserProfile" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "UserProfile" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "UserProfile" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "UserSecurityAuditLog" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "UserSecurityAuditLog" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "UserSecurityAuditLog" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "VerificationToken" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "VerificationToken" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "VerificationToken" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "Webhook" RENAME COLUMN "userId" TO "userId_old";
ALTER TABLE "Webhook" RENAME COLUMN "secondaryUserId" TO "userId";
ALTER TABLE "Webhook" DROP COLUMN "userId_old";
-- AlterTable
ALTER TABLE "TeamTransferVerification" ALTER COLUMN "userId" SET DATA TYPE TEXT;
-- AddForeignKey
ALTER TABLE "UserProfile" ADD CONSTRAINT "UserProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "UserSecurityAuditLog" ADD CONSTRAINT "UserSecurityAuditLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PasswordResetToken" ADD CONSTRAINT "PasswordResetToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Passkey" ADD CONSTRAINT "Passkey_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "VerificationToken" ADD CONSTRAINT "VerificationToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ApiToken" ADD CONSTRAINT "ApiToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Document" ADD CONSTRAINT "Document_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Team" ADD CONSTRAINT "Team_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TeamPending" ADD CONSTRAINT "TeamPending_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TeamMember" ADD CONSTRAINT "TeamMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Template" ADD CONSTRAINT "Template_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("secondaryId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "SiteSettings" ADD CONSTRAINT "SiteSettings_lastModifiedByUserId_fkey" FOREIGN KEY ("lastModifiedByUserId") REFERENCES "User"("secondaryId") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,66 @@
/*
Warnings:
- A unique constraint covering the columns `[userId,teamId]` on the table `TeamMember` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[userId]` on the table `UserProfile` will be added. If there are existing duplicate values, this will fail.
- Made the column `userId` on table `Account` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `Document` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `PasswordResetToken` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `Session` required. This step will fail if there are existing NULL values in that column.
- Made the column `ownerUserId` on table `Team` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `TeamMember` required. This step will fail if there are existing NULL values in that column.
- Made the column `ownerUserId` on table `TeamPending` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `Template` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `UserProfile` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `UserSecurityAuditLog` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `VerificationToken` required. This step will fail if there are existing NULL values in that column.
- Made the column `userId` on table `Webhook` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "Account" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "Document" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "PasswordResetToken" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "Session" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "Team" ALTER COLUMN "ownerUserId" SET NOT NULL;
-- AlterTable
ALTER TABLE "TeamMember" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "TeamPending" ALTER COLUMN "ownerUserId" SET NOT NULL;
-- AlterTable
ALTER TABLE "Template" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "UserProfile" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "UserSecurityAuditLog" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "VerificationToken" ALTER COLUMN "userId" SET NOT NULL;
-- AlterTable
ALTER TABLE "Webhook" ALTER COLUMN "userId" SET NOT NULL;
-- CreateIndex
CREATE INDEX "Document_userId_idx" ON "Document"("userId");
-- CreateIndex
CREATE INDEX "Subscription_userId_idx" ON "Subscription"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "TeamMember_userId_teamId_key" ON "TeamMember"("userId", "teamId");
-- CreateIndex
CREATE UNIQUE INDEX "UserProfile_userId_key" ON "UserProfile"("userId");

View File

@ -0,0 +1,123 @@
/*
Warnings:
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `secondaryId` on the `User` table. All the data in the column will be lost.
- A unique constraint covering the columns `[id]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- DropForeignKey
ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey";
-- DropForeignKey
ALTER TABLE "ApiToken" DROP CONSTRAINT "ApiToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "Document" DROP CONSTRAINT "Document_userId_fkey";
-- DropForeignKey
ALTER TABLE "Passkey" DROP CONSTRAINT "Passkey_userId_fkey";
-- DropForeignKey
ALTER TABLE "PasswordResetToken" DROP CONSTRAINT "PasswordResetToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey";
-- DropForeignKey
ALTER TABLE "SiteSettings" DROP CONSTRAINT "SiteSettings_lastModifiedByUserId_fkey";
-- DropForeignKey
ALTER TABLE "Subscription" DROP CONSTRAINT "Subscription_userId_fkey";
-- DropForeignKey
ALTER TABLE "Team" DROP CONSTRAINT "Team_ownerUserId_fkey";
-- DropForeignKey
ALTER TABLE "TeamMember" DROP CONSTRAINT "TeamMember_userId_fkey";
-- DropForeignKey
ALTER TABLE "TeamPending" DROP CONSTRAINT "TeamPending_ownerUserId_fkey";
-- DropForeignKey
ALTER TABLE "Template" DROP CONSTRAINT "Template_userId_fkey";
-- DropForeignKey
ALTER TABLE "UserProfile" DROP CONSTRAINT "UserProfile_userId_fkey";
-- DropForeignKey
ALTER TABLE "UserSecurityAuditLog" DROP CONSTRAINT "UserSecurityAuditLog_userId_fkey";
-- DropForeignKey
ALTER TABLE "VerificationToken" DROP CONSTRAINT "VerificationToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_userId_fkey";
-- DropIndex
DROP INDEX "User_secondaryId_key";
-- AlterTable
ALTER TABLE "User" DROP CONSTRAINT "User_pkey";
-- Rename the id column to id_old
ALTER TABLE "User" ALTER COLUMN "id" SET DATA TYPE TEXT;
ALTER TABLE "User" ALTER COLUMN "id" DROP DEFAULT;
ALTER TABLE "User" RENAME COLUMN "id" TO "id_old";
-- Rename the secondaryId column to id
ALTER TABLE "User" RENAME COLUMN "secondaryId" TO "id";
-- Drop the id_old column
ALTER TABLE "User" DROP COLUMN "id_old";
-- CreateIndex
CREATE UNIQUE INDEX "User_id_key" ON "User"("id");
-- AddForeignKey
ALTER TABLE "UserProfile" ADD CONSTRAINT "UserProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "UserSecurityAuditLog" ADD CONSTRAINT "UserSecurityAuditLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PasswordResetToken" ADD CONSTRAINT "PasswordResetToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Passkey" ADD CONSTRAINT "Passkey_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "VerificationToken" ADD CONSTRAINT "VerificationToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ApiToken" ADD CONSTRAINT "ApiToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Document" ADD CONSTRAINT "Document_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Team" ADD CONSTRAINT "Team_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TeamPending" ADD CONSTRAINT "TeamPending_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TeamMember" ADD CONSTRAINT "TeamMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Template" ADD CONSTRAINT "Template_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "SiteSettings" ADD CONSTRAINT "SiteSettings_lastModifiedByUserId_fkey" FOREIGN KEY ("lastModifiedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View File

@ -21,10 +21,10 @@
"seed": "tsx ./seed-database.ts"
},
"dependencies": {
"@prisma/client": "5.4.2",
"kysely": "^0.27.3",
"prisma": "5.4.2",
"prisma-extension-kysely": "^2.1.0",
"@prisma/client": "^6.1.0",
"kysely": "^0.27.5",
"prisma": "^6.1.0",
"prisma-extension-kysely": "^3.0.0",
"ts-pattern": "^5.0.6"
},
"devDependencies": {
@ -33,6 +33,6 @@
"prisma-kysely": "^1.8.0",
"tsx": "^4.11.0",
"typescript": "5.2.2",
"zod-prisma-types": "^3.1.8"
"zod-prisma-types": "^3.2.1"
}
}
}

View File

@ -28,7 +28,7 @@ enum Role {
}
model User {
id Int @id @default(autoincrement())
id String @unique @default(cuid(2))
name String?
customerId String? @unique
email String @unique
@ -73,7 +73,7 @@ model User {
model UserProfile {
id String @id @default(cuid())
enabled Boolean @default(false)
userId Int @unique
userId String @unique
bio String?
User User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@ -106,8 +106,9 @@ enum UserSecurityAuditLogType {
}
model UserSecurityAuditLog {
id Int @id @default(autoincrement())
userId Int
id Int @id @default(autoincrement())
userId String
createdAt DateTime @default(now())
type UserSecurityAuditLogType
userAgent String?
@ -121,13 +122,13 @@ model PasswordResetToken {
token String @unique
createdAt DateTime @default(now())
expiry DateTime
userId Int
userId String
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model Passkey {
id String @id @default(cuid())
userId Int
userId String
name String
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
@ -157,7 +158,7 @@ model VerificationToken {
completed Boolean @default(false)
expires DateTime
createdAt DateTime @default(now())
userId Int
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
@ -178,7 +179,7 @@ model Webhook {
enabled Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
userId Int
userId String
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
teamId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
@ -215,7 +216,7 @@ model ApiToken {
algorithm ApiTokenAlgorithm @default(SHA512)
expires DateTime?
createdAt DateTime @default(now())
userId Int?
userId String?
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
teamId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
@ -233,7 +234,7 @@ model Subscription {
planId String @unique
priceId String
periodEnd DateTime?
userId Int?
userId String?
teamId Int? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@ -247,16 +248,14 @@ model Subscription {
model Account {
id String @id @default(cuid())
userId Int
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
// Some providers return created_at so we need to make it optional
created_at Int?
// Stops next-auth from crashing when dealing with AzureAD
ext_expires_in Int?
token_type String?
scope String?
@ -271,7 +270,7 @@ model Account {
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId Int
userId String
expires DateTime
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
}
@ -297,7 +296,7 @@ enum DocumentVisibility {
model Document {
id Int @id @default(autoincrement())
externalId String?
userId Int
userId String
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
authOptions Json?
formValues Json?
@ -534,14 +533,13 @@ model TeamGlobalSettings {
}
model Team {
id Int @id @default(autoincrement())
name String
url String @unique
createdAt DateTime @default(now())
avatarImageId String?
customerId String? @unique
ownerUserId Int
id Int @id @default(autoincrement())
name String
url String @unique
createdAt DateTime @default(now())
avatarImageId String?
customerId String? @unique
ownerUserId String
members TeamMember[]
invites TeamMemberInvite[]
teamEmail TeamEmail?
@ -566,7 +564,7 @@ model TeamPending {
url String @unique
createdAt DateTime @default(now())
customerId String @unique
ownerUserId Int
ownerUserId String
owner User @relation(fields: [ownerUserId], references: [id], onDelete: Cascade)
}
@ -576,7 +574,7 @@ model TeamMember {
teamId Int
createdAt DateTime @default(now())
role TeamMemberRole
userId Int
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@ -605,7 +603,7 @@ model TeamEmailVerification {
model TeamTransferVerification {
teamId Int @id @unique
userId Int
userId String
name String
email String
token String @unique
@ -658,11 +656,11 @@ model Template {
externalId String?
type TemplateType @default(PRIVATE)
title String
userId Int
userId String
teamId Int?
authOptions Json?
templateMeta TemplateMeta?
templateDocumentDataId String
templateDocumentDataId String @unique
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
publicTitle String @default("")
@ -675,8 +673,6 @@ model Template {
Field Field[]
directLink TemplateDirectLink?
documents Document[]
@@unique([templateDocumentDataId])
}
model TemplateDirectLink {
@ -695,7 +691,7 @@ model SiteSettings {
id String @id
enabled Boolean @default(false)
data Json
lastModifiedByUserId Int?
lastModifiedByUserId String?
lastModifiedAt DateTime @default(now())
lastModifiedByUser User? @relation(fields: [lastModifiedByUserId], references: [id], onDelete: SetNull)
}

View File

@ -3,7 +3,7 @@ import { prisma } from '..';
export const seedTestEmail = () => `user-${Date.now()}@test.documenso.com`;
type SeedSubscriptionOptions = {
userId: number;
userId: string;
priceId: string;
};

View File

@ -133,7 +133,7 @@ export const seedTeamMember = async ({
type UnseedTeamMemberOptions = {
teamId: number;
userId: number;
userId: string;
};
export const unseedTeamMember = async ({ teamId, userId }: UnseedTeamMemberOptions) => {
@ -147,7 +147,7 @@ export const unseedTeamMember = async ({ teamId, userId }: UnseedTeamMemberOptio
});
};
export const seedTeamTransfer = async (options: { newOwnerUserId: number; teamId: number }) => {
export const seedTeamTransfer = async (options: { newOwneruserId: string; teamId: number }) => {
return await prisma.teamTransferVerification.create({
data: {
teamId: options.teamId,

View File

@ -16,7 +16,7 @@ const examplePdf = fs
type SeedTemplateOptions = {
title?: string;
userId: number;
userId: string;
teamId?: number;
createTemplateOptions?: Partial<Prisma.TemplateCreateInput>;
};

View File

@ -45,7 +45,7 @@ export const seedUser = async ({
});
};
export const unseedUser = async (userId: number) => {
export const unseedUser = async (userId: string) => {
await prisma.user.delete({
where: {
id: userId,