add subdivision2 to schema

This commit is contained in:
Francis Cao 2023-02-16 09:52:07 -08:00
parent b6cc6cb655
commit 074fa2c5fc
6 changed files with 59 additions and 29 deletions

View File

@ -16,6 +16,7 @@ CREATE TABLE event
language LowCardinality(String),
country LowCardinality(String),
subdivision LowCardinality(String),
subdivision2 LowCardinality(String),
city String,
--pageview
url String,
@ -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,
@ -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;

View File

@ -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),

View File

@ -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])

View File

@ -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);

View File

@ -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])

23
scripts/test.js Normal file
View File

@ -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();