Skip to content

Commit

Permalink
Merge pull request #121 from sgcarstrends/120-fix-date-inserted-as-st…
Browse files Browse the repository at this point in the history
…ring-instead-of-a-timestamp

Update DB schema
  • Loading branch information
ruchernchong authored Sep 4, 2024
2 parents 94e36a2 + 00361e4 commit bfe8af2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 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
11 changes: 11 additions & 0 deletions migrations/0000_clever_havok.sql
Original file line number Diff line number Diff line change
@@ -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
);
11 changes: 0 additions & 11 deletions migrations/0000_harsh_gwen_stacy.sql

This file was deleted.

17 changes: 9 additions & 8 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": "e1f5ee58-c5a0-4ddb-bda5-acb4bf00db6a",
"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 All @@ -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": {},
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": 1725474007373,
"tag": "0000_clever_havok",
"breakpoints": true
}
]
Expand Down
14 changes: 7 additions & 7 deletions schema/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bfe8af2

Please sign in to comment.