Skip to content

Commit 0a9d031

Browse files
committed
up
1 parent 394d72a commit 0a9d031

3 files changed

Lines changed: 564 additions & 7 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to alter the column `changes` on the `audit_logs` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
5+
- You are about to alter the column `variables` on the `email_templates` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
6+
- You are about to alter the column `metaKeywords` on the `pages` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
7+
- You are about to alter the column `metadata` on the `payments` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
8+
- You are about to alter the column `countries` on the `shipping_zones` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
9+
- You are about to alter the column `metadata` on the `sync_logs` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
10+
- You are about to alter the column `events` on the `webhooks` table. The data in that column could be lost. The data in that column will be cast from `String` to `Json`.
11+
12+
*/
13+
-- RedefineTables
14+
PRAGMA defer_foreign_keys=ON;
15+
PRAGMA foreign_keys=OFF;
16+
CREATE TABLE "new_audit_logs" (
17+
"id" TEXT NOT NULL PRIMARY KEY,
18+
"storeId" TEXT,
19+
"userId" TEXT,
20+
"action" TEXT NOT NULL,
21+
"entityType" TEXT NOT NULL,
22+
"entityId" TEXT NOT NULL,
23+
"changes" JSONB,
24+
"ipAddress" TEXT,
25+
"userAgent" TEXT,
26+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
27+
CONSTRAINT "audit_logs_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
28+
CONSTRAINT "audit_logs_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE CASCADE
29+
);
30+
INSERT INTO "new_audit_logs" ("action", "changes", "createdAt", "entityId", "entityType", "id", "ipAddress", "storeId", "userAgent", "userId") SELECT "action", "changes", "createdAt", "entityId", "entityType", "id", "ipAddress", "storeId", "userAgent", "userId" FROM "audit_logs";
31+
DROP TABLE "audit_logs";
32+
ALTER TABLE "new_audit_logs" RENAME TO "audit_logs";
33+
CREATE INDEX "audit_logs_storeId_createdAt_idx" ON "audit_logs"("storeId", "createdAt");
34+
CREATE INDEX "audit_logs_userId_createdAt_idx" ON "audit_logs"("userId", "createdAt");
35+
CREATE INDEX "audit_logs_entityType_entityId_createdAt_idx" ON "audit_logs"("entityType", "entityId", "createdAt");
36+
CREATE TABLE "new_email_templates" (
37+
"id" TEXT NOT NULL PRIMARY KEY,
38+
"storeId" TEXT NOT NULL,
39+
"name" TEXT NOT NULL,
40+
"handle" TEXT NOT NULL,
41+
"subject" TEXT NOT NULL,
42+
"htmlBody" TEXT NOT NULL,
43+
"textBody" TEXT,
44+
"variables" JSONB NOT NULL,
45+
"isActive" BOOLEAN NOT NULL DEFAULT true,
46+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
47+
"updatedAt" DATETIME NOT NULL,
48+
CONSTRAINT "email_templates_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE CASCADE
49+
);
50+
INSERT INTO "new_email_templates" ("createdAt", "handle", "htmlBody", "id", "isActive", "name", "storeId", "subject", "textBody", "updatedAt", "variables") SELECT "createdAt", "handle", "htmlBody", "id", "isActive", "name", "storeId", "subject", "textBody", "updatedAt", "variables" FROM "email_templates";
51+
DROP TABLE "email_templates";
52+
ALTER TABLE "new_email_templates" RENAME TO "email_templates";
53+
CREATE INDEX "email_templates_storeId_isActive_idx" ON "email_templates"("storeId", "isActive");
54+
CREATE UNIQUE INDEX "email_templates_storeId_handle_key" ON "email_templates"("storeId", "handle");
55+
CREATE TABLE "new_pages" (
56+
"id" TEXT NOT NULL PRIMARY KEY,
57+
"storeId" TEXT NOT NULL,
58+
"title" TEXT NOT NULL,
59+
"slug" TEXT NOT NULL,
60+
"content" TEXT NOT NULL,
61+
"metaTitle" TEXT,
62+
"metaDescription" TEXT,
63+
"metaKeywords" JSONB NOT NULL,
64+
"isPublished" BOOLEAN NOT NULL DEFAULT false,
65+
"publishedAt" DATETIME,
66+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
67+
"updatedAt" DATETIME NOT NULL,
68+
"deletedAt" DATETIME,
69+
CONSTRAINT "pages_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE CASCADE
70+
);
71+
INSERT INTO "new_pages" ("content", "createdAt", "deletedAt", "id", "isPublished", "metaDescription", "metaKeywords", "metaTitle", "publishedAt", "slug", "storeId", "title", "updatedAt") SELECT "content", "createdAt", "deletedAt", "id", "isPublished", "metaDescription", "metaKeywords", "metaTitle", "publishedAt", "slug", "storeId", "title", "updatedAt" FROM "pages";
72+
DROP TABLE "pages";
73+
ALTER TABLE "new_pages" RENAME TO "pages";
74+
CREATE INDEX "pages_storeId_isPublished_idx" ON "pages"("storeId", "isPublished");
75+
CREATE INDEX "pages_storeId_deletedAt_title_idx" ON "pages"("storeId", "deletedAt", "title");
76+
CREATE UNIQUE INDEX "pages_storeId_slug_key" ON "pages"("storeId", "slug");
77+
CREATE TABLE "new_payments" (
78+
"id" TEXT NOT NULL PRIMARY KEY,
79+
"storeId" TEXT NOT NULL,
80+
"orderId" TEXT NOT NULL,
81+
"amount" REAL NOT NULL,
82+
"currency" TEXT NOT NULL DEFAULT 'USD',
83+
"status" TEXT NOT NULL DEFAULT 'PENDING',
84+
"method" TEXT NOT NULL,
85+
"gateway" TEXT NOT NULL,
86+
"gatewayPaymentId" TEXT,
87+
"gatewayCustomerId" TEXT,
88+
"gatewayChargeId" TEXT,
89+
"metadata" JSONB,
90+
"refundedAmount" REAL NOT NULL DEFAULT 0,
91+
"refundedAt" DATETIME,
92+
"failureCode" TEXT,
93+
"failureMessage" TEXT,
94+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
95+
"updatedAt" DATETIME NOT NULL,
96+
CONSTRAINT "payments_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
97+
CONSTRAINT "payments_orderId_fkey" FOREIGN KEY ("orderId") REFERENCES "orders" ("id") ON DELETE CASCADE ON UPDATE CASCADE
98+
);
99+
INSERT INTO "new_payments" ("amount", "createdAt", "currency", "failureCode", "failureMessage", "gateway", "gatewayChargeId", "gatewayCustomerId", "gatewayPaymentId", "id", "metadata", "method", "orderId", "refundedAmount", "refundedAt", "status", "storeId", "updatedAt") SELECT "amount", "createdAt", "currency", "failureCode", "failureMessage", "gateway", "gatewayChargeId", "gatewayCustomerId", "gatewayPaymentId", "id", "metadata", "method", "orderId", "refundedAmount", "refundedAt", "status", "storeId", "updatedAt" FROM "payments";
100+
DROP TABLE "payments";
101+
ALTER TABLE "new_payments" RENAME TO "payments";
102+
CREATE INDEX "payments_storeId_orderId_idx" ON "payments"("storeId", "orderId");
103+
CREATE INDEX "payments_storeId_status_idx" ON "payments"("storeId", "status");
104+
CREATE INDEX "payments_gatewayPaymentId_idx" ON "payments"("gatewayPaymentId");
105+
CREATE INDEX "payments_status_createdAt_idx" ON "payments"("status", "createdAt");
106+
CREATE INDEX "payments_gateway_status_createdAt_idx" ON "payments"("gateway", "status", "createdAt");
107+
CREATE INDEX "payments_storeId_createdAt_idx" ON "payments"("storeId", "createdAt");
108+
CREATE TABLE "new_shipping_zones" (
109+
"id" TEXT NOT NULL PRIMARY KEY,
110+
"storeId" TEXT NOT NULL,
111+
"name" TEXT NOT NULL,
112+
"countries" JSONB NOT NULL,
113+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
114+
"updatedAt" DATETIME NOT NULL,
115+
CONSTRAINT "shipping_zones_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE CASCADE
116+
);
117+
INSERT INTO "new_shipping_zones" ("countries", "createdAt", "id", "name", "storeId", "updatedAt") SELECT "countries", "createdAt", "id", "name", "storeId", "updatedAt" FROM "shipping_zones";
118+
DROP TABLE "shipping_zones";
119+
ALTER TABLE "new_shipping_zones" RENAME TO "shipping_zones";
120+
CREATE INDEX "shipping_zones_storeId_idx" ON "shipping_zones"("storeId");
121+
CREATE TABLE "new_sync_logs" (
122+
"id" TEXT NOT NULL PRIMARY KEY,
123+
"configId" TEXT NOT NULL,
124+
"entityType" TEXT NOT NULL,
125+
"action" TEXT NOT NULL,
126+
"status" TEXT NOT NULL,
127+
"recordsProcessed" INTEGER NOT NULL DEFAULT 0,
128+
"recordsFailed" INTEGER NOT NULL DEFAULT 0,
129+
"errorMessage" TEXT,
130+
"metadata" JSONB,
131+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
132+
CONSTRAINT "sync_logs_configId_fkey" FOREIGN KEY ("configId") REFERENCES "external_platform_configs" ("id") ON DELETE CASCADE ON UPDATE CASCADE
133+
);
134+
INSERT INTO "new_sync_logs" ("action", "configId", "createdAt", "entityType", "errorMessage", "id", "metadata", "recordsFailed", "recordsProcessed", "status") SELECT "action", "configId", "createdAt", "entityType", "errorMessage", "id", "metadata", "recordsFailed", "recordsProcessed", "status" FROM "sync_logs";
135+
DROP TABLE "sync_logs";
136+
ALTER TABLE "new_sync_logs" RENAME TO "sync_logs";
137+
CREATE INDEX "sync_logs_configId_createdAt_idx" ON "sync_logs"("configId", "createdAt");
138+
CREATE INDEX "sync_logs_status_createdAt_idx" ON "sync_logs"("status", "createdAt");
139+
CREATE TABLE "new_webhooks" (
140+
"id" TEXT NOT NULL PRIMARY KEY,
141+
"storeId" TEXT NOT NULL,
142+
"url" TEXT NOT NULL,
143+
"events" JSONB NOT NULL,
144+
"secret" TEXT NOT NULL,
145+
"isActive" BOOLEAN NOT NULL DEFAULT true,
146+
"lastDeliveryAt" DATETIME,
147+
"lastDeliveryStatus" TEXT,
148+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
149+
"updatedAt" DATETIME NOT NULL,
150+
CONSTRAINT "webhooks_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "stores" ("id") ON DELETE CASCADE ON UPDATE CASCADE
151+
);
152+
INSERT INTO "new_webhooks" ("createdAt", "events", "id", "isActive", "lastDeliveryAt", "lastDeliveryStatus", "secret", "storeId", "updatedAt", "url") SELECT "createdAt", "events", "id", "isActive", "lastDeliveryAt", "lastDeliveryStatus", "secret", "storeId", "updatedAt", "url" FROM "webhooks";
153+
DROP TABLE "webhooks";
154+
ALTER TABLE "new_webhooks" RENAME TO "webhooks";
155+
CREATE INDEX "webhooks_storeId_isActive_idx" ON "webhooks"("storeId", "isActive");
156+
CREATE INDEX "webhooks_isActive_lastDeliveryStatus_idx" ON "webhooks"("isActive", "lastDeliveryStatus");
157+
PRAGMA foreign_keys=ON;
158+
PRAGMA defer_foreign_keys=OFF;

prisma/schema.prisma

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ model Payment {
750750
gatewayChargeId String? // Stripe charge_id
751751
752752
// Metadata
753-
metadata String? // JSON gateway-specific data
753+
metadata Json? // Gateway-specific data object - migrated from String? in T038k
754754
755755
// Refund
756756
refundedAmount Float @default(0)
@@ -990,7 +990,7 @@ model ShippingZone {
990990
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
991991
992992
name String
993-
countries String // JSON array of ISO country codes (e.g., ["US", "CA"])
993+
countries Json // Array of ISO country codes (e.g., ["US", "CA"]) - migrated from String in T038g
994994
995995
createdAt DateTime @default(now())
996996
updatedAt DateTime @updatedAt
@@ -1069,7 +1069,7 @@ model Page {
10691069
// SEO
10701070
metaTitle String?
10711071
metaDescription String?
1072-
metaKeywords String // JSON array
1072+
metaKeywords Json // Array of keywords - migrated from String in T038h
10731073
10741074
isPublished Boolean @default(false)
10751075
publishedAt DateTime?
@@ -1141,7 +1141,7 @@ model EmailTemplate {
11411141
textBody String?
11421142
11431143
// Variables (e.g., ["{{customerName}}", "{{orderNumber}}"])
1144-
variables String // JSON array
1144+
variables Json // Array of template variables - migrated from String in T038i
11451145
11461146
isActive Boolean @default(true)
11471147
@@ -1283,7 +1283,7 @@ model SyncLog {
12831283
recordsFailed Int @default(0)
12841284
12851285
errorMessage String?
1286-
metadata String? // JSON
1286+
metadata Json? // Sync processing metadata - migrated from String? in T038l
12871287
12881288
createdAt DateTime @default(now())
12891289
@@ -1298,7 +1298,7 @@ model Webhook {
12981298
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
12991299
13001300
url String
1301-
events String // JSON array e.g., ["order.created", "product.updated"]
1301+
events Json // Array of event names e.g., ["order.created", "product.updated"] - migrated from String in T038j
13021302
secret String // For HMAC signature verification
13031303
13041304
isActive Boolean @default(true)
@@ -1332,7 +1332,7 @@ model AuditLog {
13321332
entityId String
13331333
13341334
// Change tracking
1335-
changes String? // JSON { "field": { "old": "value", "new": "value" } }
1335+
changes Json? // Object with field diffs: { "field": { "old": "value", "new": "value" } } - migrated from String? in T038m
13361336
13371337
// Request metadata
13381338
ipAddress String?

0 commit comments

Comments
 (0)