From cd2d7d8f8f65e9dc481378dd508835ebcd50f643 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 1 May 2025 17:50:02 +0300 Subject: [PATCH 1/2] PM-1156 - simplify the tolley log table, use jsonb --- .../migration.sql | 29 +++++++++++++++++++ prisma/schema.prisma | 5 +--- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 prisma/migrations/20250501144025_cleanup_trolley_log_table/migration.sql diff --git a/prisma/migrations/20250501144025_cleanup_trolley_log_table/migration.sql b/prisma/migrations/20250501144025_cleanup_trolley_log_table/migration.sql new file mode 100644 index 0000000..e3009a7 --- /dev/null +++ b/prisma/migrations/20250501144025_cleanup_trolley_log_table/migration.sql @@ -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; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 343c328..b782fab 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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 { From e6d637b168e786c6ceb01062c1396c0ce5abff6f Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 1 May 2025 17:52:01 +0300 Subject: [PATCH 2/2] new line --- prisma/migrations/migration_lock.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index 648c57f..044d57c 100644 --- a/prisma/migrations/migration_lock.toml +++ b/prisma/migrations/migration_lock.toml @@ -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" \ No newline at end of file +provider = "postgresql"