Skip to content

PM-1156 - simplify the tolley log table, use jsonb #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BEGIN;

-- Step 1: Drop unused metadata columns
ALTER TABLE "trolley_webhook_log"
DROP COLUMN "created_by",
DROP COLUMN "updated_at",
DROP COLUMN "updated_by";

-- Step 2: Add new JSONB column
ALTER TABLE "trolley_webhook_log"
ADD COLUMN "event_payload_json" JSONB;

-- Step 3: Migrate data from old stringified JSON column to new JSONB column
UPDATE "trolley_webhook_log"
SET "event_payload_json" = "event_payload"::jsonb;

-- Step 4: Drop old column
ALTER TABLE "trolley_webhook_log"
DROP COLUMN "event_payload";

-- Step 5: Rename new column to match original name
ALTER TABLE "trolley_webhook_log"
RENAME COLUMN "event_payload_json" TO "event_payload";

-- Step 6: Apply NOT NULL constraint
ALTER TABLE "trolley_webhook_log"
ALTER COLUMN "event_payload" SET NOT NULL;

COMMIT;
2 changes: 1 addition & 1 deletion prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"
provider = "postgresql"
5 changes: 1 addition & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,12 @@ model trolley_webhook_log {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
event_id String @unique
event_time DateTime @default(now()) @db.Timestamp(6)
event_payload String
event_payload Json
event_model String?
event_action String?
status webhook_status
error_message String?
created_by String? @db.VarChar(80)
updated_by String? @db.VarChar(80)
created_at DateTime? @default(now()) @db.Timestamp(6)
updated_at DateTime? @default(now()) @db.Timestamp(6)
}

model trolley_recipient_payment_method {
Expand Down