Skip to content

Commit

Permalink
add subdivision2 to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscao633 committed Feb 16, 2023
1 parent b6cc6cb commit 074fa2c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
9 changes: 6 additions & 3 deletions db/clickhouse/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CREATE TABLE event
language LowCardinality(String),
country LowCardinality(String),
subdivision LowCardinality(String),
subdivision2 LowCardinality(String),
city String,
--pageview
url String,
Expand Down Expand Up @@ -44,7 +45,8 @@ CREATE TABLE event_queue (
screen LowCardinality(String),
language LowCardinality(String),
country LowCardinality(String),
subdivision LowCardinality(String),
subdivision1 LowCardinality(String),
subdivision2 LowCardinality(String),
city String,
--pageview
url String,
Expand Down Expand Up @@ -76,13 +78,14 @@ SELECT website_id,
screen,
language,
country,
subdivision,
subdivision1,
subdivision2,
city,
url,
referrer,
page_title,
event_type,
event_name,
if((empty(event_data) = 0) AND startsWith(event_data, '"'), concat('{', event_data, ': true}'), event_data) AS event_data,
event_data,
created_at
FROM event_queue;
3 changes: 2 additions & 1 deletion db/mysql/migrations/01_init/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ CREATE TABLE `session` (
`screen` VARCHAR(11) NULL,
`language` VARCHAR(35) NULL,
`country` CHAR(2) NULL,
`subdivision` CHAR(3) NULL,
`subdivision1` CHAR(3) NULL,
`subdivision2` CHAR(3) NULL,
`city` VARCHAR(50) NULL,
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),

Expand Down
25 changes: 13 additions & 12 deletions db/mysql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ model User {
}

model Session {
id String @id @unique @map("session_id") @db.VarChar(36)
websiteId String @map("website_id") @db.VarChar(36)
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
subdivision String? @db.Char(3)
city String? @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
id String @id @unique @map("session_id") @db.VarChar(36)
websiteId String @map("website_id") @db.VarChar(36)
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
subdivision1 String? @db.Char(3)
subdivision2 String? @db.Char(3)
city String? @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
@@index([createdAt])
@@index([websiteId])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- AlterTable
ALTER TABLE "session" ADD COLUMN "city" VARCHAR(50),
ADD COLUMN "subdivision" CHAR(3);
ADD COLUMN "subdivision1" CHAR(3),
ADD COLUMN "subdivision2" CHAR(3);

-- AlterTable
ALTER TABLE "website_event" ADD COLUMN "page_title" VARCHAR(500);
25 changes: 13 additions & 12 deletions db/postgresql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ model User {
}

model Session {
id String @id @unique @map("session_id") @db.Uuid
websiteId String @map("website_id") @db.Uuid
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
subdivision String? @db.Char(3)
city String? @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
id String @id @unique @map("session_id") @db.Uuid
websiteId String @map("website_id") @db.Uuid
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
os String? @db.VarChar(20)
device String? @db.VarChar(20)
screen String? @db.VarChar(11)
language String? @db.VarChar(35)
country String? @db.Char(2)
subdivision1 String? @db.Char(3)
subdivision2 String? @db.Char(3)
city String? @db.VarChar(50)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
@@index([createdAt])
@@index([websiteId])
Expand Down
23 changes: 23 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable no-console */
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const https = require('https');
const zlib = require('zlib');
const tar = require('tar');
const maxmind = require('maxmind');

async function getLocation() {
const lookup = await maxmind.open(path.resolve('../node_modules/.geo/GeoLite2-City.mmdb'));
const result = lookup.get('104.93.28.0');

const country = result?.country?.iso_code ?? result?.registered_country?.iso_code;
const subdivision = result?.subdivisions[0].iso_code;
const subdivision2 = result?.subdivisions[0].names;
const subdivision3 = result?.subdivisions[1].names;
const city = result?.city?.names?.en;
console.log(result);
console.log(country, subdivision, city, subdivision2, subdivision3);
}

getLocation();

0 comments on commit 074fa2c

Please sign in to comment.