-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
50 lines (45 loc) · 1.89 KB
/
schema.sql
File metadata and controls
50 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- D1 Database Schema for iceberg.rest
-- Sessions table - stores encrypted credentials and session metadata
CREATE TABLE IF NOT EXISTS sessions (
session_id TEXT PRIMARY KEY,
auth_type TEXT NOT NULL, -- 'bearer', 'oauth2', 'sigv4'
encrypted_credentials TEXT NOT NULL, -- JSON string with auth credentials (encrypted)
endpoint TEXT NOT NULL,
warehouse TEXT,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
last_used_at INTEGER NOT NULL,
ip_address TEXT,
user_agent TEXT,
country TEXT
);
-- Analytics table - non-sensitive usage metrics
CREATE TABLE IF NOT EXISTS analytics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
event_type TEXT NOT NULL, -- 'page_view', 'login', 'catalog_browse', 'table_view', 'connect_view'
timestamp INTEGER NOT NULL,
session_id TEXT,
country TEXT,
city TEXT,
user_agent TEXT,
browser TEXT,
os TEXT,
metadata TEXT -- JSON string for additional event-specific data
);
-- Index for faster queries
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at);
CREATE INDEX IF NOT EXISTS idx_analytics_timestamp ON analytics(timestamp);
CREATE INDEX IF NOT EXISTS idx_analytics_event_type ON analytics(event_type);
CREATE INDEX IF NOT EXISTS idx_analytics_session ON analytics(session_id);
-- Catalog usage table - track which catalogs are being used (no credentials)
CREATE TABLE IF NOT EXISTS catalog_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL,
endpoint_domain TEXT NOT NULL, -- just the domain, not full URL
timestamp INTEGER NOT NULL,
action TEXT NOT NULL, -- 'connect', 'list_namespaces', 'list_tables', 'load_table'
success BOOLEAN NOT NULL,
response_time_ms INTEGER
);
CREATE INDEX IF NOT EXISTS idx_catalog_usage_timestamp ON catalog_usage(timestamp);
CREATE INDEX IF NOT EXISTS idx_catalog_usage_endpoint ON catalog_usage(endpoint_domain);