import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() async function main() { await prisma.$executeRaw` CREATE TYPE "TipoDocumento" AS ENUM ('PETICAO', 'CONTRATO', 'PROCURACAO', 'DECLARACAO', 'OUTROS'); -- Criar tabela de documentos CREATE TABLE IF NOT EXISTS "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 REFERENCES "processos"(id), "atendimentoId" UUID REFERENCES "atendimentos"(id), "anexoId" UUID UNIQUE REFERENCES "anexos"(id), "criadoPorId" UUID NOT NULL REFERENCES "usuarios"(id), "criadoEm" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "atualizadoEm" TIMESTAMP(3) NOT NULL, CONSTRAINT "documentos_pkey" PRIMARY KEY ("id") ); -- Criar tabela de modelos de documentos CREATE TABLE IF NOT EXISTS "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[] DEFAULT ARRAY[]::TEXT[], "criadoEm" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "atualizadoEm" TIMESTAMP(3) NOT NULL, CONSTRAINT "documentos_modelos_pkey" PRIMARY KEY ("id") ); -- Criar índices CREATE INDEX "documentos_processoId_idx" ON "documentos"("processoId"); CREATE INDEX "documentos_atendimentoId_idx" ON "documentos"("atendimentoId"); `; } main() .catch(e => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });