Initial Mento CRM: portal OTP, reports, SMS, and deploy for crm.montzar.ir.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "QuoteStatus" AS ENUM ('draft', 'sent', 'accepted', 'rejected', 'expired');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Quote" (
|
||||
"id" TEXT NOT NULL,
|
||||
"organizationId" TEXT NOT NULL,
|
||||
"number" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"status" "QuoteStatus" NOT NULL DEFAULT 'draft',
|
||||
"currency" TEXT NOT NULL DEFAULT 'IRR',
|
||||
"notes" TEXT,
|
||||
"validUntil" TIMESTAMP(3),
|
||||
"personId" TEXT,
|
||||
"companyId" TEXT,
|
||||
"dealId" TEXT,
|
||||
"ownerId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Quote_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "QuoteLineItem" (
|
||||
"id" TEXT NOT NULL,
|
||||
"quoteId" TEXT NOT NULL,
|
||||
"productId" TEXT,
|
||||
"name" TEXT NOT NULL,
|
||||
"quantity" DECIMAL(18,2) NOT NULL DEFAULT 1,
|
||||
"unitPrice" DECIMAL(18,2) NOT NULL,
|
||||
"currency" TEXT NOT NULL DEFAULT 'IRR',
|
||||
"position" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "QuoteLineItem_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Quote_organizationId_status_updatedAt_idx" ON "Quote"("organizationId", "status", "updatedAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Quote_personId_idx" ON "Quote"("personId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Quote_companyId_idx" ON "Quote"("companyId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Quote_dealId_idx" ON "Quote"("dealId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Quote_ownerId_idx" ON "Quote"("ownerId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Quote_organizationId_number_key" ON "Quote"("organizationId", "number");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "QuoteLineItem_quoteId_position_idx" ON "QuoteLineItem"("quoteId", "position");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "QuoteLineItem_productId_idx" ON "QuoteLineItem"("productId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Quote" ADD CONSTRAINT "Quote_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Quote" ADD CONSTRAINT "Quote_personId_fkey" FOREIGN KEY ("personId") REFERENCES "Person"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Quote" ADD CONSTRAINT "Quote_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Quote" ADD CONSTRAINT "Quote_dealId_fkey" FOREIGN KEY ("dealId") REFERENCES "Deal"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Quote" ADD CONSTRAINT "Quote_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "QuoteLineItem" ADD CONSTRAINT "QuoteLineItem_quoteId_fkey" FOREIGN KEY ("quoteId") REFERENCES "Quote"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "QuoteLineItem" ADD CONSTRAINT "QuoteLineItem_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
Reference in New Issue
Block a user