|
| 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; |
0 commit comments