From fddd0f6c80df77162e8c169abab56e30d0148c2e Mon Sep 17 00:00:00 2001 From: mrkarimoff Date: Thu, 1 Feb 2024 21:21:58 +0500 Subject: [PATCH] add formatting event to insert --- apps/analytics/app/api/event/route.ts | 10 ++- ...chers.sql => 0000_uneven_madame_hydra.sql} | 2 +- .../drizzle/0001_fine_randall_flagg.sql | 2 - .../analytics/drizzle/meta/0000_snapshot.json | 8 +- .../analytics/drizzle/meta/0001_snapshot.json | 87 ------------------- apps/analytics/drizzle/meta/_journal.json | 11 +-- 6 files changed, 15 insertions(+), 105 deletions(-) rename apps/analytics/drizzle/{0000_yellow_the_watchers.sql => 0000_uneven_madame_hydra.sql} (90%) delete mode 100644 apps/analytics/drizzle/0001_fine_randall_flagg.sql delete mode 100644 apps/analytics/drizzle/meta/0001_snapshot.json diff --git a/apps/analytics/app/api/event/route.ts b/apps/analytics/app/api/event/route.ts index 5ca26750..abd65540 100644 --- a/apps/analytics/app/api/event/route.ts +++ b/apps/analytics/app/api/event/route.ts @@ -22,12 +22,18 @@ export async function POST(request: NextRequest) { ); } - const eventWithDate = { + const formattedEvent = { ...parsedEvent.data, + ...(parsedEvent.data.type === "Error" && { + type: "Error", + message: parsedEvent.data.error.message, + name: parsedEvent.data.error.name, + stack: parsedEvent.data.error.stack, + }), timestamp: new Date(parsedEvent.data.timestamp), // Convert back into a date object }; - const result = await insertEvent(eventWithDate); + const result = await insertEvent(formattedEvent); if (result.error) { return NextResponse.json( diff --git a/apps/analytics/drizzle/0000_yellow_the_watchers.sql b/apps/analytics/drizzle/0000_uneven_madame_hydra.sql similarity index 90% rename from apps/analytics/drizzle/0000_yellow_the_watchers.sql rename to apps/analytics/drizzle/0000_uneven_madame_hydra.sql index fbc2c0ff..dee771d2 100644 --- a/apps/analytics/drizzle/0000_yellow_the_watchers.sql +++ b/apps/analytics/drizzle/0000_uneven_madame_hydra.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS "events" ( "type" text NOT NULL, "installationId" text NOT NULL, "timestamp" timestamp NOT NULL, - "isocode" text, + "countryISOCode" text NOT NULL, "message" text, "name" text, "stack" text, diff --git a/apps/analytics/drizzle/0001_fine_randall_flagg.sql b/apps/analytics/drizzle/0001_fine_randall_flagg.sql deleted file mode 100644 index 22e73e73..00000000 --- a/apps/analytics/drizzle/0001_fine_randall_flagg.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE "events" RENAME COLUMN "isocode" TO "countryISOCode";--> statement-breakpoint -ALTER TABLE "events" ALTER COLUMN "countryISOCode" SET NOT NULL; \ No newline at end of file diff --git a/apps/analytics/drizzle/meta/0000_snapshot.json b/apps/analytics/drizzle/meta/0000_snapshot.json index 857f0bc0..46356ecf 100644 --- a/apps/analytics/drizzle/meta/0000_snapshot.json +++ b/apps/analytics/drizzle/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "8314d6f3-51e8-44a2-a9ec-d3128c1a7775", + "id": "13cbb638-62c2-4e6a-aef8-a17910f27456", "prevId": "00000000-0000-0000-0000-000000000000", "version": "5", "dialect": "pg", @@ -32,11 +32,11 @@ "primaryKey": false, "notNull": true }, - "isocode": { - "name": "isocode", + "countryISOCode": { + "name": "countryISOCode", "type": "text", "primaryKey": false, - "notNull": false + "notNull": true }, "message": { "name": "message", diff --git a/apps/analytics/drizzle/meta/0001_snapshot.json b/apps/analytics/drizzle/meta/0001_snapshot.json deleted file mode 100644 index a849161a..00000000 --- a/apps/analytics/drizzle/meta/0001_snapshot.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "id": "4b38aa70-169b-4c8f-b5f2-ed833c57d04a", - "prevId": "8314d6f3-51e8-44a2-a9ec-d3128c1a7775", - "version": "5", - "dialect": "pg", - "tables": { - "events": { - "name": "events", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "installationId": { - "name": "installationId", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "timestamp": { - "name": "timestamp", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "countryISOCode": { - "name": "countryISOCode", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "message": { - "name": "message", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "metadata": { - "name": "metadata", - "type": "json", - "primaryKey": false, - "notNull": false - } - }, - "indexes": { - "unique_idx": { - "name": "unique_idx", - "columns": [ - "id" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/apps/analytics/drizzle/meta/_journal.json b/apps/analytics/drizzle/meta/_journal.json index 7e441e89..9ca00956 100644 --- a/apps/analytics/drizzle/meta/_journal.json +++ b/apps/analytics/drizzle/meta/_journal.json @@ -5,15 +5,8 @@ { "idx": 0, "version": "5", - "when": 1706248816583, - "tag": "0000_yellow_the_watchers", - "breakpoints": true - }, - { - "idx": 1, - "version": "5", - "when": 1706786115080, - "tag": "0001_fine_randall_flagg", + "when": 1706803795839, + "tag": "0000_uneven_madame_hydra", "breakpoints": true } ]