Skip to content

Commit 7f856a5

Browse files
authored
Merge pull request #41 from topcoder-platform/PM-1156_simplify-trolley-log-table
PM-1156 - simplify the tolley log table, use jsonb
2 parents 303df82 + e6d637b commit 7f856a5

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BEGIN;
2+
3+
-- Step 1: Drop unused metadata columns
4+
ALTER TABLE "trolley_webhook_log"
5+
DROP COLUMN "created_by",
6+
DROP COLUMN "updated_at",
7+
DROP COLUMN "updated_by";
8+
9+
-- Step 2: Add new JSONB column
10+
ALTER TABLE "trolley_webhook_log"
11+
ADD COLUMN "event_payload_json" JSONB;
12+
13+
-- Step 3: Migrate data from old stringified JSON column to new JSONB column
14+
UPDATE "trolley_webhook_log"
15+
SET "event_payload_json" = "event_payload"::jsonb;
16+
17+
-- Step 4: Drop old column
18+
ALTER TABLE "trolley_webhook_log"
19+
DROP COLUMN "event_payload";
20+
21+
-- Step 5: Rename new column to match original name
22+
ALTER TABLE "trolley_webhook_log"
23+
RENAME COLUMN "event_payload_json" TO "event_payload";
24+
25+
-- Step 6: Apply NOT NULL constraint
26+
ALTER TABLE "trolley_webhook_log"
27+
ALTER COLUMN "event_payload" SET NOT NULL;
28+
29+
COMMIT;

prisma/migrations/migration_lock.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
22
# It should be added in your version-control system (e.g., Git)
3-
provider = "postgresql"
3+
provider = "postgresql"

prisma/schema.prisma

+1-4
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,12 @@ model trolley_webhook_log {
204204
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
205205
event_id String @unique
206206
event_time DateTime @default(now()) @db.Timestamp(6)
207-
event_payload String
207+
event_payload Json
208208
event_model String?
209209
event_action String?
210210
status webhook_status
211211
error_message String?
212-
created_by String? @db.VarChar(80)
213-
updated_by String? @db.VarChar(80)
214212
created_at DateTime? @default(now()) @db.Timestamp(6)
215-
updated_at DateTime? @default(now()) @db.Timestamp(6)
216213
}
217214

218215
model trolley_recipient_payment_method {

0 commit comments

Comments
 (0)