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_clever_havok.sql b/migrations/0000_clever_havok.sql new file mode 100644 index 0000000..901df31 --- /dev/null +++ b/migrations/0000_clever_havok.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS "analytics" ( + "id" serial PRIMARY KEY NOT NULL, + "date" timestamp with time zone DEFAULT now(), + "pathname" text NOT NULL, + "referrer" text, + "country" text, + "flag" text, + "city" text, + "latitude" text, + "longitude" text +); diff --git a/migrations/0000_harsh_gwen_stacy.sql b/migrations/0000_harsh_gwen_stacy.sql deleted file mode 100644 index be0fef8..0000000 --- a/migrations/0000_harsh_gwen_stacy.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE IF NOT EXISTS "analytics" ( - "id" serial PRIMARY KEY NOT NULL, - "date" timestamp with time zone NOT NULL, - "pathname" text NOT NULL, - "referrer" text NOT NULL, - "country" text NOT NULL, - "flag" text NOT NULL, - "city" text NOT NULL, - "latitude" text NOT NULL, - "longitude" text NOT NULL -); diff --git a/migrations/meta/0000_snapshot.json b/migrations/meta/0000_snapshot.json index 6ff5841..4588aaf 100644 --- a/migrations/meta/0000_snapshot.json +++ b/migrations/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "3c6472be-ac7a-440e-a941-4856bc665b88", + "id": "e1f5ee58-c5a0-4ddb-bda5-acb4bf00db6a", "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", @@ -30,37 +31,37 @@ "name": "referrer", "type": "text", "primaryKey": false, - "notNull": true + "notNull": false }, "country": { "name": "country", "type": "text", "primaryKey": false, - "notNull": true + "notNull": false }, "flag": { "name": "flag", "type": "text", "primaryKey": false, - "notNull": true + "notNull": false }, "city": { "name": "city", "type": "text", "primaryKey": false, - "notNull": true + "notNull": false }, "latitude": { "name": "latitude", "type": "text", "primaryKey": false, - "notNull": true + "notNull": false }, "longitude": { "name": "longitude", "type": "text", "primaryKey": false, - "notNull": true + "notNull": false } }, "indexes": {}, diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index 64bb089..91f6646 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": 1725474007373, + "tag": "0000_clever_havok", "breakpoints": true } ] diff --git a/schema/analytics.ts b/schema/analytics.ts index 02336c0..b215e7f 100644 --- a/schema/analytics.ts +++ b/schema/analytics.ts @@ -2,14 +2,14 @@ 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(), - flag: text("flag").notNull(), - city: text("city").notNull(), - latitude: text("latitude").notNull(), - longitude: text("longitude").notNull(), + referrer: text("referrer"), + country: text("country"), + flag: text("flag"), + city: text("city"), + latitude: text("latitude"), + longitude: text("longitude"), }); export type InsertAnalytics = typeof analyticsTable.$inferInsert;