diff --git a/app/api/analytics/route.ts b/app/api/analytics/route.ts index 6393aec..377e3f6 100644 --- a/app/api/analytics/route.ts +++ b/app/api/analytics/route.ts @@ -9,7 +9,6 @@ interface RequestData { } export const POST = async (request: NextRequest) => { - const date = new Date(); const { pathname, referrer }: RequestData = await request.json(); const { country, flag, city, latitude, longitude } = geolocation(request); @@ -18,7 +17,6 @@ export const POST = async (request: NextRequest) => { } const dataToInsert: InsertAnalytics = { - date, pathname, referrer, country, diff --git a/migrations/0000_harsh_gwen_stacy.sql b/migrations/0000_fancy_miek.sql similarity index 84% rename from migrations/0000_harsh_gwen_stacy.sql rename to migrations/0000_fancy_miek.sql index be0fef8..9972ef6 100644 --- a/migrations/0000_harsh_gwen_stacy.sql +++ b/migrations/0000_fancy_miek.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS "analytics" ( "id" serial PRIMARY KEY NOT NULL, - "date" timestamp with time zone NOT NULL, + "date" timestamp with time zone DEFAULT now(), "pathname" text NOT NULL, "referrer" text NOT NULL, "country" text NOT NULL, diff --git a/migrations/meta/0000_snapshot.json b/migrations/meta/0000_snapshot.json index 6ff5841..bec58bd 100644 --- a/migrations/meta/0000_snapshot.json +++ b/migrations/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "3c6472be-ac7a-440e-a941-4856bc665b88", + "id": "f2f720ea-f979-4c80-8756-e2b63ff699cc", "prevId": "00000000-0000-0000-0000-000000000000", "version": "7", "dialect": "postgresql", @@ -18,7 +18,8 @@ "name": "date", "type": "timestamp with time zone", "primaryKey": false, - "notNull": true + "notNull": false, + "default": "now()" }, "pathname": { "name": "pathname", diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index 64bb089..8fc0aa1 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -5,8 +5,8 @@ { "idx": 0, "version": "7", - "when": 1725128427172, - "tag": "0000_harsh_gwen_stacy", + "when": 1725471294545, + "tag": "0000_fancy_miek", "breakpoints": true } ] diff --git a/schema/analytics.ts b/schema/analytics.ts index 02336c0..e55d857 100644 --- a/schema/analytics.ts +++ b/schema/analytics.ts @@ -2,7 +2,7 @@ import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; export const analyticsTable = pgTable("analytics", { id: serial("id").primaryKey(), - date: timestamp("date", { withTimezone: true }).notNull(), + date: timestamp("date", { withTimezone: true }).defaultNow(), pathname: text("pathname").notNull(), referrer: text("referrer").notNull(), country: text("country").notNull(),