This commit is contained in:
David Nguyen
2025-05-07 15:03:20 +10:00
parent 419bc02171
commit 7abfc9e271
390 changed files with 21254 additions and 12607 deletions

View File

@ -0,0 +1,238 @@
/*
Warnings:
- You are about to drop the column `teamId` on the `Subscription` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `Subscription` table. All the data in the column will be lost.
- You are about to drop the column `customerId` on the `Team` table. All the data in the column will be lost.
- You are about to drop the column `ownerUserId` on the `Team` table. All the data in the column will be lost.
- You are about to drop the column `url` on the `User` table. All the data in the column will be lost.
- You are about to drop the `TeamMember` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `TeamMemberInvite` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `TeamTransferVerification` table. If the table is not empty, all the data it contains will be lost.
- Made the column `teamId` on table `Document` required. This step will fail if there are existing NULL values in that column.
- Added the required column `organisationId` to the `Subscription` table without a default value. This is not possible if the table is not empty.
- Added the required column `organisationId` to the `Team` table without a default value. This is not possible if the table is not empty.
- Made the column `teamId` on table `Template` required. This step will fail if there are existing NULL values in that column.
*/
-- CreateEnum
CREATE TYPE "OrganisationGroupType" AS ENUM ('INTERNAL_ORGANISATION', 'INTERNAL_TEAM', 'CUSTOM');
-- CreateEnum
CREATE TYPE "OrganisationMemberRole" AS ENUM ('ADMIN', 'MANAGER', 'MEMBER');
-- CreateEnum
CREATE TYPE "OrganisationMemberInviteStatus" AS ENUM ('ACCEPTED', 'PENDING', 'DECLINED');
-- DropForeignKey
ALTER TABLE "Document" DROP CONSTRAINT "Document_teamId_fkey";
-- DropForeignKey
ALTER TABLE "Subscription" DROP CONSTRAINT "Subscription_teamId_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_teamId_fkey";
-- DropForeignKey
ALTER TABLE "TeamMember" DROP CONSTRAINT "TeamMember_userId_fkey";
-- DropForeignKey
ALTER TABLE "TeamMemberInvite" DROP CONSTRAINT "TeamMemberInvite_teamId_fkey";
-- DropForeignKey
ALTER TABLE "TeamTransferVerification" DROP CONSTRAINT "TeamTransferVerification_teamId_fkey";
-- DropIndex
DROP INDEX "Subscription_teamId_key";
-- DropIndex
DROP INDEX "Subscription_userId_idx";
-- DropIndex
DROP INDEX "Team_customerId_key";
-- DropIndex
DROP INDEX "User_url_key";
-- AlterTable
ALTER TABLE "ApiToken" ADD COLUMN "organisationId" TEXT;
-- AlterTable
ALTER TABLE "Document" ALTER COLUMN "teamId" SET NOT NULL;
-- AlterTable
ALTER TABLE "Subscription" DROP COLUMN "teamId",
DROP COLUMN "userId",
ADD COLUMN "organisationId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "Team" DROP COLUMN "customerId",
DROP COLUMN "ownerUserId",
ADD COLUMN "organisationId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "Template" ALTER COLUMN "teamId" SET NOT NULL;
-- AlterTable
ALTER TABLE "User" DROP COLUMN "url";
-- AlterTable
ALTER TABLE "Webhook" ADD COLUMN "organisationId" TEXT;
-- DropTable
DROP TABLE "TeamMember";
-- DropTable
DROP TABLE "TeamMemberInvite";
-- DropTable
DROP TABLE "TeamTransferVerification";
-- DropEnum
DROP TYPE "TeamMemberInviteStatus";
-- CreateTable
CREATE TABLE "Organisation" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"name" TEXT NOT NULL,
"url" TEXT NOT NULL,
"avatarImageId" TEXT,
"customerId" TEXT,
"ownerUserId" INTEGER NOT NULL,
CONSTRAINT "Organisation_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "OrganisationMember" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"userId" INTEGER NOT NULL,
"organisationId" TEXT NOT NULL,
CONSTRAINT "OrganisationMember_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "OrganisationMemberInvite" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"email" TEXT NOT NULL,
"token" TEXT NOT NULL,
"groupIds" TEXT[],
"status" "OrganisationMemberInviteStatus" NOT NULL DEFAULT 'PENDING',
"organisationId" TEXT NOT NULL,
"organisationRole" "OrganisationMemberRole" NOT NULL,
"teamId" INTEGER,
"teamRole" "TeamMemberRole",
CONSTRAINT "OrganisationMemberInvite_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "OrganisationGroup" (
"id" TEXT NOT NULL,
"name" TEXT,
"type" "OrganisationGroupType" NOT NULL,
"organisationRole" "OrganisationMemberRole" NOT NULL,
"organisationId" TEXT NOT NULL,
CONSTRAINT "OrganisationGroup_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "OrganisationGroupMember" (
"id" TEXT NOT NULL,
"groupId" TEXT NOT NULL,
"organisationMemberId" TEXT,
CONSTRAINT "OrganisationGroupMember_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "TeamGroup" (
"id" TEXT NOT NULL,
"organisationGroupId" TEXT NOT NULL,
"teamRole" "TeamMemberRole" NOT NULL,
"teamId" INTEGER NOT NULL,
CONSTRAINT "TeamGroup_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Organisation_url_key" ON "Organisation"("url");
-- CreateIndex
CREATE UNIQUE INDEX "Organisation_customerId_key" ON "Organisation"("customerId");
-- CreateIndex
CREATE UNIQUE INDEX "OrganisationMember_userId_organisationId_key" ON "OrganisationMember"("userId", "organisationId");
-- CreateIndex
CREATE UNIQUE INDEX "OrganisationMemberInvite_token_key" ON "OrganisationMemberInvite"("token");
-- CreateIndex
CREATE UNIQUE INDEX "OrganisationGroupMember_organisationMemberId_groupId_key" ON "OrganisationGroupMember"("organisationMemberId", "groupId");
-- CreateIndex
CREATE INDEX "Subscription_organisationId_idx" ON "Subscription"("organisationId");
-- CreateIndex
CREATE INDEX "Template_userId_idx" ON "Template"("userId");
-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ApiToken" ADD CONSTRAINT "ApiToken_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Document" ADD CONSTRAINT "Document_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Organisation" ADD CONSTRAINT "Organisation_avatarImageId_fkey" FOREIGN KEY ("avatarImageId") REFERENCES "AvatarImage"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Organisation" ADD CONSTRAINT "Organisation_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationMember" ADD CONSTRAINT "OrganisationMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationMember" ADD CONSTRAINT "OrganisationMember_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationMemberInvite" ADD CONSTRAINT "OrganisationMemberInvite_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationMemberInvite" ADD CONSTRAINT "OrganisationMemberInvite_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationGroup" ADD CONSTRAINT "OrganisationGroup_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationGroupMember" ADD CONSTRAINT "OrganisationGroupMember_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "OrganisationGroup"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OrganisationGroupMember" ADD CONSTRAINT "OrganisationGroupMember_organisationMemberId_fkey" FOREIGN KEY ("organisationMemberId") REFERENCES "OrganisationMember"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TeamGroup" ADD CONSTRAINT "TeamGroup_organisationGroupId_fkey" FOREIGN KEY ("organisationGroupId") REFERENCES "OrganisationGroup"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TeamGroup" ADD CONSTRAINT "TeamGroup_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Team" ADD CONSTRAINT "Team_organisationId_fkey" FOREIGN KEY ("organisationId") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,14 @@
/*
Warnings:
- Made the column `organisationMemberId` on table `OrganisationGroupMember` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE "OrganisationGroupMember" DROP CONSTRAINT "OrganisationGroupMember_organisationMemberId_fkey";
-- AlterTable
ALTER TABLE "OrganisationGroupMember" ALTER COLUMN "organisationMemberId" SET NOT NULL;
-- AddForeignKey
ALTER TABLE "OrganisationGroupMember" ADD CONSTRAINT "OrganisationGroupMember_organisationMemberId_fkey" FOREIGN KEY ("organisationMemberId") REFERENCES "OrganisationMember"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE "OrganisationGroupMember" DROP CONSTRAINT "OrganisationGroupMember_organisationMemberId_fkey";
-- AddForeignKey
ALTER TABLE "OrganisationGroupMember" ADD CONSTRAINT "OrganisationGroupMember_organisationMemberId_fkey" FOREIGN KEY ("organisationMemberId") REFERENCES "OrganisationMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,17 @@
/*
Warnings:
- You are about to drop the column `teamId` on the `OrganisationMemberInvite` table. All the data in the column will be lost.
- You are about to drop the column `teamRole` on the `OrganisationMemberInvite` table. All the data in the column will be lost.
- A unique constraint covering the columns `[teamId,organisationGroupId]` on the table `TeamGroup` will be added. If there are existing duplicate values, this will fail.
*/
-- DropForeignKey
ALTER TABLE "OrganisationMemberInvite" DROP CONSTRAINT "OrganisationMemberInvite_teamId_fkey";
-- AlterTable
ALTER TABLE "OrganisationMemberInvite" DROP COLUMN "teamId",
DROP COLUMN "teamRole";
-- CreateIndex
CREATE UNIQUE INDEX "TeamGroup_teamId_organisationGroupId_key" ON "TeamGroup"("teamId", "organisationGroupId");

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `groupIds` on the `OrganisationMemberInvite` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "OrganisationMemberInvite" DROP COLUMN "groupIds";

View File

@ -0,0 +1,82 @@
/*
Warnings:
- You are about to drop the column `teamId` on the `TeamGlobalSettings` table. All the data in the column will be lost.
- A unique constraint covering the columns `[settingsId]` on the table `Organisation` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[settingsId]` on the table `Team` will be added. If there are existing duplicate values, this will fail.
- Added the required column `settingsId` to the `Organisation` table without a default value. This is not possible if the table is not empty.
- Added the required column `settingsId` to the `Team` table without a default value. This is not possible if the table is not empty.
- The required column `id` was added to the `TeamGlobalSettings` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
*/
-- DropForeignKey
ALTER TABLE "TeamGlobalSettings" DROP CONSTRAINT "TeamGlobalSettings_teamId_fkey";
-- DropIndex
DROP INDEX "TeamGlobalSettings_teamId_key";
-- AlterTable
ALTER TABLE "Organisation" ADD COLUMN "settingsId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "Team" ADD COLUMN "settingsId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "TeamGlobalSettings" DROP COLUMN "teamId",
ADD COLUMN "id" TEXT NOT NULL,
ALTER COLUMN "documentVisibility" DROP NOT NULL,
ALTER COLUMN "documentVisibility" DROP DEFAULT,
ALTER COLUMN "includeSenderDetails" DROP NOT NULL,
ALTER COLUMN "includeSenderDetails" DROP DEFAULT,
ALTER COLUMN "brandingCompanyDetails" DROP NOT NULL,
ALTER COLUMN "brandingCompanyDetails" DROP DEFAULT,
ALTER COLUMN "brandingEnabled" DROP NOT NULL,
ALTER COLUMN "brandingEnabled" DROP DEFAULT,
ALTER COLUMN "brandingHidePoweredBy" DROP NOT NULL,
ALTER COLUMN "brandingHidePoweredBy" DROP DEFAULT,
ALTER COLUMN "brandingLogo" DROP NOT NULL,
ALTER COLUMN "brandingLogo" DROP DEFAULT,
ALTER COLUMN "brandingUrl" DROP NOT NULL,
ALTER COLUMN "brandingUrl" DROP DEFAULT,
ALTER COLUMN "documentLanguage" DROP NOT NULL,
ALTER COLUMN "documentLanguage" DROP DEFAULT,
ALTER COLUMN "typedSignatureEnabled" DROP NOT NULL,
ALTER COLUMN "typedSignatureEnabled" DROP DEFAULT,
ALTER COLUMN "includeSigningCertificate" DROP NOT NULL,
ALTER COLUMN "includeSigningCertificate" DROP DEFAULT,
ALTER COLUMN "drawSignatureEnabled" DROP NOT NULL,
ALTER COLUMN "drawSignatureEnabled" DROP DEFAULT,
ALTER COLUMN "uploadSignatureEnabled" DROP NOT NULL,
ALTER COLUMN "uploadSignatureEnabled" DROP DEFAULT,
ADD CONSTRAINT "TeamGlobalSettings_pkey" PRIMARY KEY ("id");
-- CreateTable
CREATE TABLE "OrganisationGlobalSettings" (
"id" TEXT NOT NULL,
"documentVisibility" "DocumentVisibility" NOT NULL DEFAULT 'EVERYONE',
"documentLanguage" TEXT NOT NULL DEFAULT 'en',
"includeSenderDetails" BOOLEAN NOT NULL DEFAULT true,
"includeSigningCertificate" BOOLEAN NOT NULL DEFAULT true,
"typedSignatureEnabled" BOOLEAN NOT NULL DEFAULT true,
"uploadSignatureEnabled" BOOLEAN NOT NULL DEFAULT true,
"drawSignatureEnabled" BOOLEAN NOT NULL DEFAULT true,
"brandingEnabled" BOOLEAN NOT NULL DEFAULT false,
"brandingLogo" TEXT NOT NULL DEFAULT '',
"brandingUrl" TEXT NOT NULL DEFAULT '',
"brandingCompanyDetails" TEXT NOT NULL DEFAULT '',
"brandingHidePoweredBy" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "OrganisationGlobalSettings_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Organisation_settingsId_key" ON "Organisation"("settingsId");
-- CreateIndex
CREATE UNIQUE INDEX "Team_settingsId_key" ON "Team"("settingsId");
-- AddForeignKey
ALTER TABLE "Organisation" ADD CONSTRAINT "Organisation_settingsId_fkey" FOREIGN KEY ("settingsId") REFERENCES "OrganisationGlobalSettings"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Team" ADD CONSTRAINT "Team_settingsId_fkey" FOREIGN KEY ("settingsId") REFERENCES "TeamGlobalSettings"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,42 @@
/*
Warnings:
- You are about to drop the column `settingsId` on the `Organisation` table. All the data in the column will be lost.
- You are about to drop the column `settingsId` on the `Team` table. All the data in the column will be lost.
- A unique constraint covering the columns `[organisationGlobalSettingsId]` on the table `Organisation` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[teamGlobalSettingsId]` on the table `Team` will be added. If there are existing duplicate values, this will fail.
- Added the required column `organisationGlobalSettingsId` to the `Organisation` table without a default value. This is not possible if the table is not empty.
- Added the required column `teamGlobalSettingsId` to the `Team` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "Organisation" DROP CONSTRAINT "Organisation_settingsId_fkey";
-- DropForeignKey
ALTER TABLE "Team" DROP CONSTRAINT "Team_settingsId_fkey";
-- DropIndex
DROP INDEX "Organisation_settingsId_key";
-- DropIndex
DROP INDEX "Team_settingsId_key";
-- AlterTable
ALTER TABLE "Organisation" DROP COLUMN "settingsId",
ADD COLUMN "organisationGlobalSettingsId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "Team" DROP COLUMN "settingsId",
ADD COLUMN "teamGlobalSettingsId" TEXT NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX "Organisation_organisationGlobalSettingsId_key" ON "Organisation"("organisationGlobalSettingsId");
-- CreateIndex
CREATE UNIQUE INDEX "Team_teamGlobalSettingsId_key" ON "Team"("teamGlobalSettingsId");
-- AddForeignKey
ALTER TABLE "Organisation" ADD CONSTRAINT "Organisation_organisationGlobalSettingsId_fkey" FOREIGN KEY ("organisationGlobalSettingsId") REFERENCES "OrganisationGlobalSettings"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Team" ADD CONSTRAINT "Team_teamGlobalSettingsId_fkey" FOREIGN KEY ("teamGlobalSettingsId") REFERENCES "TeamGlobalSettings"("id") ON DELETE CASCADE ON UPDATE CASCADE;