/* Warnings: - You are about to drop the `Documento` table. If the table is not empty, all the data it contains will be lost. */ -- CreateEnum CREATE TYPE "TipoDocumento" AS ENUM ('PETICAO', 'CONTRATO', 'PROCURACAO', 'DECLARACAO', 'OUTROS'); -- DropForeignKey ALTER TABLE "Documento" DROP CONSTRAINT "Documento_processoId_fkey"; -- DropTable DROP TABLE "Documento"; -- CreateTable CREATE TABLE "documentos" ( "id" UUID NOT NULL DEFAULT gen_random_uuid(), "nome" VARCHAR(200) NOT NULL, "tipo" "TipoDocumento" NOT NULL, "conteudo" TEXT NOT NULL, "url" TEXT, "processoId" UUID, "atendimentoId" UUID, "anexoId" UUID, "criadoPorId" UUID NOT NULL, "criadoEm" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "atualizadoEm" TIMESTAMP(3) NOT NULL, CONSTRAINT "documentos_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "documentos_modelos" ( "id" UUID NOT NULL DEFAULT gen_random_uuid(), "nome" VARCHAR(200) NOT NULL, "descricao" TEXT, "tipo" "TipoDocumento" NOT NULL, "conteudo" TEXT NOT NULL, "variaveis" TEXT[], "criadoEm" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "atualizadoEm" TIMESTAMP(3) NOT NULL, CONSTRAINT "documentos_modelos_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "documentos_anexoId_key" ON "documentos"("anexoId"); -- CreateIndex CREATE INDEX "documentos_processoId_idx" ON "documentos"("processoId"); -- CreateIndex CREATE INDEX "documentos_atendimentoId_idx" ON "documentos"("atendimentoId"); -- AddForeignKey ALTER TABLE "documentos" ADD CONSTRAINT "documentos_processoId_fkey" FOREIGN KEY ("processoId") REFERENCES "Processo"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "documentos" ADD CONSTRAINT "documentos_atendimentoId_fkey" FOREIGN KEY ("atendimentoId") REFERENCES "atendimentos"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "documentos" ADD CONSTRAINT "documentos_anexoId_fkey" FOREIGN KEY ("anexoId") REFERENCES "Anexo"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "documentos" ADD CONSTRAINT "documentos_criadoPorId_fkey" FOREIGN KEY ("criadoPorId") REFERENCES "usuarios"("id") ON DELETE RESTRICT ON UPDATE CASCADE;