Skip to content

Commit 20b0bda

Browse files
authored
Merge pull request #3 from MicroPyramid/dev
Dev
2 parents 20f98a1 + b3cb4e9 commit 20b0bda

File tree

17 files changed

+2376
-135
lines changed

17 files changed

+2376
-135
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `addressId` on the `Account` table. All the data in the column will be lost.
5+
- You are about to drop the column `accountId` on the `Contact` table. All the data in the column will be lost.
6+
- You are about to drop the column `addressId` on the `Contact` table. All the data in the column will be lost.
7+
- You are about to drop the column `billingAddressId` on the `Quote` table. All the data in the column will be lost.
8+
- You are about to drop the column `shippingAddressId` on the `Quote` table. All the data in the column will be lost.
9+
- You are about to drop the `Address` table. If the table is not empty, all the data it contains will be lost.
10+
11+
*/
12+
-- DropForeignKey
13+
ALTER TABLE "Account" DROP CONSTRAINT "Account_addressId_fkey";
14+
15+
-- DropForeignKey
16+
ALTER TABLE "Contact" DROP CONSTRAINT "Contact_accountId_fkey";
17+
18+
-- DropForeignKey
19+
ALTER TABLE "Contact" DROP CONSTRAINT "Contact_addressId_fkey";
20+
21+
-- DropForeignKey
22+
ALTER TABLE "Quote" DROP CONSTRAINT "QuoteBillingAddress_fk";
23+
24+
-- DropForeignKey
25+
ALTER TABLE "Quote" DROP CONSTRAINT "QuoteShippingAddress_fk";
26+
27+
-- AlterTable
28+
ALTER TABLE "Account" DROP COLUMN "addressId",
29+
ADD COLUMN "city" TEXT,
30+
ADD COLUMN "country" TEXT,
31+
ADD COLUMN "latitude" DOUBLE PRECISION,
32+
ADD COLUMN "longitude" DOUBLE PRECISION,
33+
ADD COLUMN "postalCode" TEXT,
34+
ADD COLUMN "state" TEXT,
35+
ADD COLUMN "street" TEXT;
36+
37+
-- AlterTable
38+
ALTER TABLE "Contact" DROP COLUMN "accountId",
39+
DROP COLUMN "addressId",
40+
ADD COLUMN "city" TEXT,
41+
ADD COLUMN "country" TEXT,
42+
ADD COLUMN "latitude" DOUBLE PRECISION,
43+
ADD COLUMN "longitude" DOUBLE PRECISION,
44+
ADD COLUMN "postalCode" TEXT,
45+
ADD COLUMN "state" TEXT,
46+
ADD COLUMN "street" TEXT;
47+
48+
-- AlterTable
49+
ALTER TABLE "Quote" DROP COLUMN "billingAddressId",
50+
DROP COLUMN "shippingAddressId",
51+
ADD COLUMN "billingCity" TEXT,
52+
ADD COLUMN "billingCountry" TEXT,
53+
ADD COLUMN "billingPostalCode" TEXT,
54+
ADD COLUMN "billingState" TEXT,
55+
ADD COLUMN "billingStreet" TEXT,
56+
ADD COLUMN "shippingCity" TEXT,
57+
ADD COLUMN "shippingCountry" TEXT,
58+
ADD COLUMN "shippingPostalCode" TEXT,
59+
ADD COLUMN "shippingState" TEXT,
60+
ADD COLUMN "shippingStreet" TEXT;
61+
62+
-- DropTable
63+
DROP TABLE "Address";
64+
65+
-- CreateTable
66+
CREATE TABLE "AccountContactRelationship" (
67+
"id" TEXT NOT NULL,
68+
"role" TEXT,
69+
"isPrimary" BOOLEAN NOT NULL DEFAULT false,
70+
"startDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
71+
"endDate" TIMESTAMP(3),
72+
"description" TEXT,
73+
"accountId" TEXT NOT NULL,
74+
"contactId" TEXT NOT NULL,
75+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
76+
"updatedAt" TIMESTAMP(3) NOT NULL,
77+
78+
CONSTRAINT "AccountContactRelationship_pkey" PRIMARY KEY ("id")
79+
);
80+
81+
-- CreateIndex
82+
CREATE INDEX "AccountContactRelationship_contactId_idx" ON "AccountContactRelationship"("contactId");
83+
84+
-- CreateIndex
85+
CREATE INDEX "AccountContactRelationship_accountId_idx" ON "AccountContactRelationship"("accountId");
86+
87+
-- CreateIndex
88+
CREATE UNIQUE INDEX "AccountContactRelationship_contactId_accountId_key" ON "AccountContactRelationship"("contactId", "accountId");
89+
90+
-- AddForeignKey
91+
ALTER TABLE "AccountContactRelationship" ADD CONSTRAINT "AccountContactRelationship_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
92+
93+
-- AddForeignKey
94+
ALTER TABLE "AccountContactRelationship" ADD CONSTRAINT "AccountContactRelationship_contactId_fkey" FOREIGN KEY ("contactId") REFERENCES "Contact"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- AlterTable
2+
ALTER TABLE "Account" ADD COLUMN "closedAt" TIMESTAMP(3),
3+
ADD COLUMN "closureReason" TEXT,
4+
ADD COLUMN "deletedAt" TIMESTAMP(3),
5+
ADD COLUMN "deletedById" TEXT,
6+
ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT true,
7+
ADD COLUMN "isDeleted" BOOLEAN NOT NULL DEFAULT false;
8+
9+
-- AddForeignKey
10+
ALTER TABLE "Account" ADD CONSTRAINT "Account_deletedById_fkey" FOREIGN KEY ("deletedById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- CreateEnum
2+
CREATE TYPE "AuditAction" AS ENUM ('CREATE', 'UPDATE', 'DELETE', 'LOGIN', 'LOGOUT', 'EXPORT', 'IMPORT', 'VIEW', 'OTHER');
3+
4+
-- CreateTable
5+
CREATE TABLE "AuditLog" (
6+
"id" TEXT NOT NULL,
7+
"timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"action" "AuditAction" NOT NULL,
9+
"entityType" TEXT NOT NULL,
10+
"entityId" TEXT,
11+
"description" TEXT,
12+
"oldValues" JSONB,
13+
"newValues" JSONB,
14+
"ipAddress" TEXT,
15+
"userAgent" TEXT,
16+
"userId" TEXT NOT NULL,
17+
"organizationId" TEXT NOT NULL,
18+
19+
CONSTRAINT "AuditLog_pkey" PRIMARY KEY ("id")
20+
);
21+
22+
-- CreateIndex
23+
CREATE INDEX "AuditLog_timestamp_idx" ON "AuditLog"("timestamp");
24+
25+
-- CreateIndex
26+
CREATE INDEX "AuditLog_entityType_entityId_idx" ON "AuditLog"("entityType", "entityId");
27+
28+
-- CreateIndex
29+
CREATE INDEX "AuditLog_userId_idx" ON "AuditLog"("userId");
30+
31+
-- CreateIndex
32+
CREATE INDEX "AuditLog_organizationId_idx" ON "AuditLog"("organizationId");
33+
34+
-- CreateIndex
35+
CREATE INDEX "AuditLog_action_idx" ON "AuditLog"("action");
36+
37+
-- AddForeignKey
38+
ALTER TABLE "AuditLog" ADD CONSTRAINT "AuditLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
39+
40+
-- AddForeignKey
41+
ALTER TABLE "AuditLog" ADD CONSTRAINT "AuditLog_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

0 commit comments

Comments
 (0)