Skip to content

Commit

Permalink
Update DB date defaults to now
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Sep 4, 2024
1 parent 94e36a2 commit 141778f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions app/api/analytics/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -18,7 +17,6 @@ export const POST = async (request: NextRequest) => {
}

const dataToInsert: InsertAnalytics = {
date,
pathname,
referrer,
country,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 3 additions & 2 deletions migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -18,7 +18,8 @@
"name": "date",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
"notNull": false,
"default": "now()"
},
"pathname": {
"name": "pathname",
Expand Down
4 changes: 2 additions & 2 deletions migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "7",
"when": 1725128427172,
"tag": "0000_harsh_gwen_stacy",
"when": 1725471294545,
"tag": "0000_fancy_miek",
"breakpoints": true
}
]
Expand Down
2 changes: 1 addition & 1 deletion schema/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 141778f

Please sign in to comment.