From 972c20f906c1c1b56265e8428a6bd1188a0db4ff Mon Sep 17 00:00:00 2001 From: Mythie Date: Thu, 21 Dec 2023 21:20:37 +1100 Subject: [PATCH] chore: tidy migrations --- .../20231007013737_templates/migration.sql | 52 ------------- .../migration.sql | 15 ---- .../migration.sql | 14 ---- .../migration.sql | 8 -- .../migration.sql | 8 -- .../migration.sql | 9 --- .../migration.sql | 51 ------------- .../20231017042227_fix_typo/migration.sql | 23 ------ .../migration.sql | 8 -- .../migration.sql | 8 -- .../migration.sql | 5 -- .../migration.sql | 10 --- .../migration.sql | 54 -------------- .../migration.sql | 8 -- .../migration.sql | 12 --- .../migration.sql | 73 +++++++++++++++++++ 16 files changed, 73 insertions(+), 285 deletions(-) delete mode 100644 packages/prisma/migrations/20231007013737_templates/migration.sql delete mode 100644 packages/prisma/migrations/20231007014431_templates_type/migration.sql delete mode 100644 packages/prisma/migrations/20231007021427_reuse_document_data/migration.sql delete mode 100644 packages/prisma/migrations/20231007033447_remove_inserted_on_template_field/migration.sql delete mode 100644 packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql delete mode 100644 packages/prisma/migrations/20231007211915_template_created_date/migration.sql delete mode 100644 packages/prisma/migrations/20231017041643_placeholder_recipients/migration.sql delete mode 100644 packages/prisma/migrations/20231017042227_fix_typo/migration.sql delete mode 100644 packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql delete mode 100644 packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql delete mode 100644 packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql delete mode 100644 packages/prisma/migrations/20231030061522_recipient_name_not_placeholder/migration.sql delete mode 100644 packages/prisma/migrations/20231208090322_remove_template_specific_models/migration.sql delete mode 100644 packages/prisma/migrations/20231214081915_remove_template_token_column/migration.sql delete mode 100644 packages/prisma/migrations/20231221070056_make_recipient_status_columns_non_null_again/migration.sql create mode 100644 packages/prisma/migrations/20231221101005_add_templates/migration.sql diff --git a/packages/prisma/migrations/20231007013737_templates/migration.sql b/packages/prisma/migrations/20231007013737_templates/migration.sql deleted file mode 100644 index e0c1bf4ec..000000000 --- a/packages/prisma/migrations/20231007013737_templates/migration.sql +++ /dev/null @@ -1,52 +0,0 @@ --- CreateEnum -CREATE TYPE "TemplateStatus" AS ENUM ('PUBLIC', 'PRIVATE'); - --- CreateTable -CREATE TABLE "Template" ( - "id" SERIAL NOT NULL, - "userId" INTEGER NOT NULL, - "title" TEXT NOT NULL, - "description" TEXT, - "status" "TemplateStatus" NOT NULL DEFAULT 'PRIVATE', - "templateDataId" TEXT NOT NULL, - - CONSTRAINT "Template_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TemplateData" ( - "id" TEXT NOT NULL, - "type" "DocumentDataType" NOT NULL, - "data" TEXT NOT NULL, - "initialData" TEXT NOT NULL, - - CONSTRAINT "TemplateData_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TemplateField" ( - "id" SERIAL NOT NULL, - "templateId" INTEGER NOT NULL, - "type" "FieldType" NOT NULL, - "page" INTEGER NOT NULL, - "positionX" DECIMAL(65,30) NOT NULL DEFAULT 0, - "positionY" DECIMAL(65,30) NOT NULL DEFAULT 0, - "width" DECIMAL(65,30) NOT NULL DEFAULT -1, - "height" DECIMAL(65,30) NOT NULL DEFAULT -1, - "customText" TEXT NOT NULL, - "inserted" BOOLEAN NOT NULL, - - CONSTRAINT "TemplateField_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "Template_templateDataId_key" ON "Template"("templateDataId"); - --- AddForeignKey -ALTER TABLE "Template" ADD CONSTRAINT "Template_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDataId_fkey" FOREIGN KEY ("templateDataId") REFERENCES "TemplateData"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TemplateField" ADD CONSTRAINT "TemplateField_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/prisma/migrations/20231007014431_templates_type/migration.sql b/packages/prisma/migrations/20231007014431_templates_type/migration.sql deleted file mode 100644 index c89e09a61..000000000 --- a/packages/prisma/migrations/20231007014431_templates_type/migration.sql +++ /dev/null @@ -1,15 +0,0 @@ -/* - Warnings: - - - The `status` column on the `Template` table would be dropped and recreated. This will lead to data loss if there is data in the column. - -*/ --- CreateEnum -CREATE TYPE "TemplateType" AS ENUM ('PUBLIC', 'PRIVATE'); - --- AlterTable -ALTER TABLE "Template" DROP COLUMN "status", -ADD COLUMN "status" "TemplateType" NOT NULL DEFAULT 'PRIVATE'; - --- DropEnum -DROP TYPE "TemplateStatus"; diff --git a/packages/prisma/migrations/20231007021427_reuse_document_data/migration.sql b/packages/prisma/migrations/20231007021427_reuse_document_data/migration.sql deleted file mode 100644 index 629f292fc..000000000 --- a/packages/prisma/migrations/20231007021427_reuse_document_data/migration.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* - Warnings: - - - You are about to drop the `TemplateData` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropForeignKey -ALTER TABLE "Template" DROP CONSTRAINT "Template_templateDataId_fkey"; - --- DropTable -DROP TABLE "TemplateData"; - --- AddForeignKey -ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDataId_fkey" FOREIGN KEY ("templateDataId") REFERENCES "DocumentData"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/prisma/migrations/20231007033447_remove_inserted_on_template_field/migration.sql b/packages/prisma/migrations/20231007033447_remove_inserted_on_template_field/migration.sql deleted file mode 100644 index 25ace4f72..000000000 --- a/packages/prisma/migrations/20231007033447_remove_inserted_on_template_field/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `inserted` on the `TemplateField` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "TemplateField" DROP COLUMN "inserted"; diff --git a/packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql b/packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql deleted file mode 100644 index 45a52de3d..000000000 --- a/packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - Added the required column `documentName` to the `Template` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "Template" ADD COLUMN "documentName" TEXT NOT NULL; diff --git a/packages/prisma/migrations/20231007211915_template_created_date/migration.sql b/packages/prisma/migrations/20231007211915_template_created_date/migration.sql deleted file mode 100644 index 816da092e..000000000 --- a/packages/prisma/migrations/20231007211915_template_created_date/migration.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* - Warnings: - - - Added the required column `updatedAt` to the `Template` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "Template" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, -ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL; diff --git a/packages/prisma/migrations/20231017041643_placeholder_recipients/migration.sql b/packages/prisma/migrations/20231017041643_placeholder_recipients/migration.sql deleted file mode 100644 index b84a567c8..000000000 --- a/packages/prisma/migrations/20231017041643_placeholder_recipients/migration.sql +++ /dev/null @@ -1,51 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `description` on the `Template` table. All the data in the column will be lost. - - You are about to drop the column `documentName` on the `Template` table. All the data in the column will be lost. - - You are about to drop the column `status` on the `Template` table. All the data in the column will be lost. - - You are about to drop the column `templateDataId` on the `Template` table. All the data in the column will be lost. - - A unique constraint covering the columns `[tempateDocumentDataId]` on the table `Template` will be added. If there are existing duplicate values, this will fail. - - Added the required column `tempateDocumentDataId` to the `Template` table without a default value. This is not possible if the table is not empty. - - Added the required column `inserted` to the `TemplateField` table without a default value. This is not possible if the table is not empty. - -*/ --- DropForeignKey -ALTER TABLE "Template" DROP CONSTRAINT "Template_templateDataId_fkey"; - --- DropIndex -DROP INDEX "Template_templateDataId_key"; - --- AlterTable -ALTER TABLE "Template" DROP COLUMN "description", -DROP COLUMN "documentName", -DROP COLUMN "status", -DROP COLUMN "templateDataId", -ADD COLUMN "tempateDocumentDataId" TEXT NOT NULL, -ADD COLUMN "type" "TemplateType" NOT NULL DEFAULT 'PRIVATE', -ALTER COLUMN "updatedAt" SET DEFAULT CURRENT_TIMESTAMP; - --- AlterTable -ALTER TABLE "TemplateField" ADD COLUMN "inserted" BOOLEAN NOT NULL, -ADD COLUMN "recipientId" INTEGER; - --- CreateTable -CREATE TABLE "TemplateRecipient" ( - "id" SERIAL NOT NULL, - "templateId" INTEGER NOT NULL, - "placeholder" VARCHAR(255) NOT NULL, - - CONSTRAINT "TemplateRecipient_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "Template_tempateDocumentDataId_key" ON "Template"("tempateDocumentDataId"); - --- AddForeignKey -ALTER TABLE "Template" ADD CONSTRAINT "Template_tempateDocumentDataId_fkey" FOREIGN KEY ("tempateDocumentDataId") REFERENCES "DocumentData"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TemplateRecipient" ADD CONSTRAINT "TemplateRecipient_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TemplateField" ADD CONSTRAINT "TemplateField_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "TemplateRecipient"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/prisma/migrations/20231017042227_fix_typo/migration.sql b/packages/prisma/migrations/20231017042227_fix_typo/migration.sql deleted file mode 100644 index ac9eaf10e..000000000 --- a/packages/prisma/migrations/20231017042227_fix_typo/migration.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `tempateDocumentDataId` on the `Template` table. All the data in the column will be lost. - - A unique constraint covering the columns `[templateDocumentDataId]` on the table `Template` will be added. If there are existing duplicate values, this will fail. - - Added the required column `templateDocumentDataId` to the `Template` table without a default value. This is not possible if the table is not empty. - -*/ --- DropForeignKey -ALTER TABLE "Template" DROP CONSTRAINT "Template_tempateDocumentDataId_fkey"; - --- DropIndex -DROP INDEX "Template_tempateDocumentDataId_key"; - --- AlterTable -ALTER TABLE "Template" DROP COLUMN "tempateDocumentDataId", -ADD COLUMN "templateDocumentDataId" TEXT NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX "Template_templateDocumentDataId_key" ON "Template"("templateDocumentDataId"); - --- AddForeignKey -ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDocumentDataId_fkey" FOREIGN KEY ("templateDocumentDataId") REFERENCES "DocumentData"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql b/packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql deleted file mode 100644 index 266333794..000000000 --- a/packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - Added the required column `email` to the `TemplateRecipient` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "TemplateRecipient" ADD COLUMN "email" VARCHAR(255) NOT NULL; diff --git a/packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql b/packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql deleted file mode 100644 index 9ce1fa70a..000000000 --- a/packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - Added the required column `token` to the `TemplateRecipient` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "TemplateRecipient" ADD COLUMN "token" TEXT NOT NULL; diff --git a/packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql b/packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql deleted file mode 100644 index a6b3e7199..000000000 --- a/packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterTable -ALTER TABLE "Recipient" ADD COLUMN "templateToken" TEXT; - --- AlterTable -ALTER TABLE "TemplateRecipient" ADD COLUMN "templateToken" TEXT; diff --git a/packages/prisma/migrations/20231030061522_recipient_name_not_placeholder/migration.sql b/packages/prisma/migrations/20231030061522_recipient_name_not_placeholder/migration.sql deleted file mode 100644 index 8b9275c68..000000000 --- a/packages/prisma/migrations/20231030061522_recipient_name_not_placeholder/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `placeholder` on the `TemplateRecipient` table. All the data in the column will be lost. - - Added the required column `name` to the `TemplateRecipient` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "TemplateRecipient" DROP COLUMN "placeholder", -ADD COLUMN "name" VARCHAR(255) NOT NULL; diff --git a/packages/prisma/migrations/20231208090322_remove_template_specific_models/migration.sql b/packages/prisma/migrations/20231208090322_remove_template_specific_models/migration.sql deleted file mode 100644 index 7e2af3ef8..000000000 --- a/packages/prisma/migrations/20231208090322_remove_template_specific_models/migration.sql +++ /dev/null @@ -1,54 +0,0 @@ -/* - Warnings: - - - You are about to drop the `TemplateField` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `TemplateRecipient` table. If the table is not empty, all the data it contains will be lost. - - A unique constraint covering the columns `[templateId,email]` on the table `Recipient` will be added. If there are existing duplicate values, this will fail. - -*/ --- DropForeignKey -ALTER TABLE "Field" DROP CONSTRAINT "Field_recipientId_fkey"; - --- DropForeignKey -ALTER TABLE "TemplateField" DROP CONSTRAINT "TemplateField_recipientId_fkey"; - --- DropForeignKey -ALTER TABLE "TemplateField" DROP CONSTRAINT "TemplateField_templateId_fkey"; - --- DropForeignKey -ALTER TABLE "TemplateRecipient" DROP CONSTRAINT "TemplateRecipient_templateId_fkey"; - --- AlterTable -ALTER TABLE "Field" ADD COLUMN "templateId" INTEGER, -ALTER COLUMN "documentId" DROP NOT NULL; - --- AlterTable -ALTER TABLE "Recipient" ADD COLUMN "templateId" INTEGER, -ALTER COLUMN "documentId" DROP NOT NULL, -ALTER COLUMN "readStatus" DROP NOT NULL, -ALTER COLUMN "signingStatus" DROP NOT NULL, -ALTER COLUMN "sendStatus" DROP NOT NULL; - --- DropTable -DROP TABLE "TemplateField"; - --- DropTable -DROP TABLE "TemplateRecipient"; - --- CreateIndex -CREATE INDEX "Field_templateId_idx" ON "Field"("templateId"); - --- CreateIndex -CREATE INDEX "Recipient_templateId_idx" ON "Recipient"("templateId"); - --- CreateIndex -CREATE UNIQUE INDEX "Recipient_templateId_email_key" ON "Recipient"("templateId", "email"); - --- AddForeignKey -ALTER TABLE "Recipient" ADD CONSTRAINT "Recipient_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Field" ADD CONSTRAINT "Field_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Field" ADD CONSTRAINT "Field_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "Recipient"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/packages/prisma/migrations/20231214081915_remove_template_token_column/migration.sql b/packages/prisma/migrations/20231214081915_remove_template_token_column/migration.sql deleted file mode 100644 index 8514a14b7..000000000 --- a/packages/prisma/migrations/20231214081915_remove_template_token_column/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `templateToken` on the `Recipient` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "Recipient" DROP COLUMN "templateToken"; diff --git a/packages/prisma/migrations/20231221070056_make_recipient_status_columns_non_null_again/migration.sql b/packages/prisma/migrations/20231221070056_make_recipient_status_columns_non_null_again/migration.sql deleted file mode 100644 index d2ebc6405..000000000 --- a/packages/prisma/migrations/20231221070056_make_recipient_status_columns_non_null_again/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* - Warnings: - - - Made the column `readStatus` on table `Recipient` required. This step will fail if there are existing NULL values in that column. - - Made the column `signingStatus` on table `Recipient` required. This step will fail if there are existing NULL values in that column. - - Made the column `sendStatus` on table `Recipient` required. This step will fail if there are existing NULL values in that column. - -*/ --- AlterTable -ALTER TABLE "Recipient" ALTER COLUMN "readStatus" SET NOT NULL, -ALTER COLUMN "signingStatus" SET NOT NULL, -ALTER COLUMN "sendStatus" SET NOT NULL; diff --git a/packages/prisma/migrations/20231221101005_add_templates/migration.sql b/packages/prisma/migrations/20231221101005_add_templates/migration.sql new file mode 100644 index 000000000..21b0a2918 --- /dev/null +++ b/packages/prisma/migrations/20231221101005_add_templates/migration.sql @@ -0,0 +1,73 @@ +/* + Warnings: + + - A unique constraint covering the columns `[templateId,email]` on the table `Recipient` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateEnum +CREATE TYPE "TemplateType" AS ENUM ('PUBLIC', 'PRIVATE'); + +-- DropForeignKey +ALTER TABLE "Field" DROP CONSTRAINT "Field_recipientId_fkey"; + +-- AlterTable +ALTER TABLE "Field" ADD COLUMN "templateId" INTEGER, +ALTER COLUMN "documentId" DROP NOT NULL; + +-- AlterTable +-- Add CHECK constraint to ensure that only one of the two columns is set +ALTER TABLE "Field" ADD CONSTRAINT "Field_templateId_documentId_check" CHECK ( + ("templateId" IS NULL AND "documentId" IS NOT NULL) OR + ("templateId" IS NOT NULL AND "documentId" IS NULL) +); + +-- AlterTable +ALTER TABLE "Recipient" ADD COLUMN "templateId" INTEGER, +ALTER COLUMN "documentId" DROP NOT NULL; + +-- AlterTable +-- Add CHECK constraint to ensure that only one of the two columns is set +ALTER TABLE "Recipient" ADD CONSTRAINT "Recipient_templateId_documentId_check" CHECK ( + ("templateId" IS NULL AND "documentId" IS NOT NULL) OR + ("templateId" IS NOT NULL AND "documentId" IS NULL) +); + +-- CreateTable +CREATE TABLE "Template" ( + "id" SERIAL NOT NULL, + "type" "TemplateType" NOT NULL DEFAULT 'PRIVATE', + "title" TEXT NOT NULL, + "userId" INTEGER NOT NULL, + "templateDocumentDataId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Template_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Template_templateDocumentDataId_key" ON "Template"("templateDocumentDataId"); + +-- CreateIndex +CREATE INDEX "Field_templateId_idx" ON "Field"("templateId"); + +-- CreateIndex +CREATE INDEX "Recipient_templateId_idx" ON "Recipient"("templateId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Recipient_templateId_email_key" ON "Recipient"("templateId", "email"); + +-- AddForeignKey +ALTER TABLE "Recipient" ADD CONSTRAINT "Recipient_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Field" ADD CONSTRAINT "Field_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Field" ADD CONSTRAINT "Field_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "Recipient"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Template" ADD CONSTRAINT "Template_templateDocumentDataId_fkey" FOREIGN KEY ("templateDocumentDataId") REFERENCES "DocumentData"("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;