Skip to content

Commit 569da2c

Browse files
committed
feat: models in infra
1 parent c7e103a commit 569da2c

File tree

6 files changed

+260
-0
lines changed

6 files changed

+260
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- ============================================================================
2+
-- Blocked Traffic Table
3+
-- ============================================================================
4+
-- Records of blocked requests, bots, and suspicious traffic patterns
5+
-- Includes TTL for automatic cleanup after 6 months
6+
-- ============================================================================
7+
8+
CREATE TABLE IF NOT EXISTS analytics.blocked_traffic (
9+
id UUID,
10+
client_id String,
11+
timestamp DateTime64(3, 'UTC'),
12+
13+
-- Request information
14+
path Nullable(String),
15+
url Nullable(String),
16+
referrer Nullable(String),
17+
method LowCardinality(String) DEFAULT 'POST',
18+
origin Nullable(String),
19+
20+
-- Client information
21+
ip String,
22+
user_agent Nullable(String),
23+
accept_header Nullable(String),
24+
language Nullable(String),
25+
26+
-- Blocking details
27+
block_reason LowCardinality(String),
28+
block_category LowCardinality(String),
29+
bot_name Nullable(String),
30+
31+
-- Geographic information
32+
country Nullable(String),
33+
region Nullable(String),
34+
35+
-- Device information
36+
browser_name Nullable(String),
37+
browser_version Nullable(String),
38+
os_name Nullable(String),
39+
os_version Nullable(String),
40+
device_type Nullable(String),
41+
42+
-- Request details
43+
payload_size Nullable(UInt32),
44+
45+
created_at DateTime64(3, 'UTC') DEFAULT now()
46+
) ENGINE = MergeTree()
47+
PARTITION BY toYYYYMM(timestamp)
48+
ORDER BY (timestamp, client_id, id)
49+
TTL toDateTime(timestamp) + INTERVAL 6 MONTH
50+
SETTINGS index_granularity = 8192;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- ============================================================================
2+
-- Custom Events Table
3+
-- ============================================================================
4+
-- User-defined custom events and tracking data beyond standard page views
5+
-- ============================================================================
6+
7+
CREATE TABLE IF NOT EXISTS analytics.custom_events (
8+
id UUID,
9+
client_id String,
10+
event_name String,
11+
anonymous_id String,
12+
session_id String,
13+
properties JSON,
14+
timestamp DateTime64(3, 'UTC') DEFAULT now()
15+
) ENGINE = MergeTree()
16+
PARTITION BY toYYYYMM(timestamp)
17+
ORDER BY (client_id, timestamp, id)
18+
SETTINGS index_granularity = 8192;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
-- ============================================================================
2+
-- Errors Table
3+
-- ============================================================================
4+
-- JavaScript errors and exceptions captured from client-side applications
5+
-- ============================================================================
6+
7+
CREATE TABLE IF NOT EXISTS analytics.errors (
8+
id UUID,
9+
client_id String,
10+
event_id Nullable(String),
11+
12+
-- User identification
13+
anonymous_id String,
14+
session_id String,
15+
timestamp DateTime64(3, 'UTC'),
16+
17+
-- Page information
18+
path String,
19+
20+
-- Error details
21+
message String,
22+
filename Nullable(String),
23+
lineno Nullable(Int32),
24+
colno Nullable(Int32),
25+
stack Nullable(String),
26+
error_type Nullable(String),
27+
28+
-- User information
29+
ip Nullable(String),
30+
user_agent Nullable(String),
31+
browser_name Nullable(String),
32+
browser_version Nullable(String),
33+
os_name Nullable(String),
34+
os_version Nullable(String),
35+
device_type Nullable(String),
36+
37+
-- Geographic information
38+
country Nullable(String),
39+
region Nullable(String),
40+
41+
created_at DateTime64(3, 'UTC')
42+
) ENGINE = MergeTree()
43+
PARTITION BY toYYYYMM(timestamp)
44+
ORDER BY (client_id, timestamp, id)
45+
SETTINGS index_granularity = 8192;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
-- ============================================================================
2+
-- Events Table
3+
-- ============================================================================
4+
-- Main analytics events table storing all user interactions and page views
5+
-- ============================================================================
6+
7+
CREATE TABLE IF NOT EXISTS analytics.events (
8+
id UUID,
9+
client_id String,
10+
event_name String,
11+
anonymous_id String,
12+
time DateTime64(3, 'UTC'),
13+
session_id String,
14+
15+
-- Event metadata
16+
event_type LowCardinality(String) DEFAULT 'track',
17+
event_id Nullable(String),
18+
session_start_time Nullable(DateTime64(3, 'UTC')),
19+
timestamp DateTime64(3, 'UTC') DEFAULT time,
20+
21+
-- Page information
22+
referrer Nullable(String),
23+
url String,
24+
path String,
25+
title Nullable(String),
26+
27+
-- User information
28+
ip String,
29+
user_agent String,
30+
browser_name Nullable(String),
31+
browser_version Nullable(String),
32+
os_name Nullable(String),
33+
os_version Nullable(String),
34+
device_type Nullable(String),
35+
device_brand Nullable(String),
36+
device_model Nullable(String),
37+
38+
-- Geographic information
39+
country Nullable(String),
40+
region Nullable(String),
41+
city Nullable(String),
42+
43+
-- Device specifications
44+
screen_resolution Nullable(String),
45+
viewport_size Nullable(String),
46+
language Nullable(String),
47+
timezone Nullable(String),
48+
49+
-- Network information
50+
connection_type Nullable(String),
51+
rtt Nullable(Int16),
52+
downlink Nullable(Float32),
53+
54+
-- User behavior metrics
55+
time_on_page Nullable(Float32),
56+
scroll_depth Nullable(Float32),
57+
interaction_count Nullable(Int16),
58+
page_count UInt8 DEFAULT 1,
59+
60+
-- UTM parameters
61+
utm_source Nullable(String),
62+
utm_medium Nullable(String),
63+
utm_campaign Nullable(String),
64+
utm_term Nullable(String),
65+
utm_content Nullable(String),
66+
67+
-- Performance metrics
68+
load_time Nullable(Int32),
69+
dom_ready_time Nullable(Int32),
70+
dom_interactive Nullable(Int32),
71+
ttfb Nullable(Int32),
72+
connection_time Nullable(Int32),
73+
request_time Nullable(Int32),
74+
render_time Nullable(Int32),
75+
redirect_time Nullable(Int32),
76+
domain_lookup_time Nullable(Int32),
77+
78+
-- Additional data
79+
properties String,
80+
created_at DateTime64(3, 'UTC')
81+
) ENGINE = MergeTree()
82+
PARTITION BY toYYYYMM(time)
83+
ORDER BY (client_id, time, id)
84+
SETTINGS index_granularity = 8192;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- ============================================================================
2+
-- Outgoing Links Table
3+
-- ============================================================================
4+
-- External link clicks and outbound traffic tracking
5+
-- ============================================================================
6+
7+
CREATE TABLE IF NOT EXISTS analytics.outgoing_links (
8+
id UUID,
9+
client_id String,
10+
anonymous_id String,
11+
session_id String,
12+
href String,
13+
text Nullable(String),
14+
properties JSON,
15+
timestamp DateTime64(3, 'UTC') DEFAULT now()
16+
) ENGINE = MergeTree()
17+
PARTITION BY toYYYYMM(timestamp)
18+
ORDER BY (client_id, timestamp, id)
19+
SETTINGS index_granularity = 8192;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- ============================================================================
2+
-- Web Vitals Table
3+
-- ============================================================================
4+
-- Core Web Vitals metrics for measuring user experience and page performance
5+
-- ============================================================================
6+
7+
CREATE TABLE IF NOT EXISTS analytics.web_vitals (
8+
id UUID,
9+
client_id String,
10+
event_id Nullable(String),
11+
12+
-- User identification
13+
anonymous_id String,
14+
session_id String,
15+
timestamp DateTime64(3, 'UTC'),
16+
17+
-- Page information
18+
path String,
19+
20+
-- Core Web Vitals
21+
fcp Nullable(Int32), -- First Contentful Paint
22+
lcp Nullable(Int32), -- Largest Contentful Paint
23+
cls Nullable(Float32), -- Cumulative Layout Shift
24+
fid Nullable(Int32), -- First Input Delay
25+
inp Nullable(Int32), -- Interaction to Next Paint
26+
27+
-- User information
28+
ip Nullable(String),
29+
user_agent Nullable(String),
30+
browser_name Nullable(String),
31+
browser_version Nullable(String),
32+
os_name Nullable(String),
33+
os_version Nullable(String),
34+
device_type Nullable(String),
35+
36+
-- Geographic information
37+
country Nullable(String),
38+
region Nullable(String),
39+
40+
created_at DateTime64(3, 'UTC')
41+
) ENGINE = MergeTree()
42+
PARTITION BY toYYYYMM(timestamp)
43+
ORDER BY (client_id, timestamp, id)
44+
SETTINGS index_granularity = 8192;

0 commit comments

Comments
 (0)