You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.8 KiB
MySQL
80 lines
3.8 KiB
MySQL
|
2 months ago
|
-- Import into the log database configured by log_db_database.
|
||
|
|
|
||
|
|
CREATE TABLE IF NOT EXISTS `site_visit_events` (
|
||
|
|
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||
|
|
`event_key` char(64) NOT NULL,
|
||
|
|
`event_type` varchar(16) NOT NULL,
|
||
|
|
`visitor_id` char(32) NOT NULL,
|
||
|
|
`session_id` char(32) NOT NULL,
|
||
|
|
`user_id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`site_host` varchar(255) NOT NULL,
|
||
|
|
`landing_path` varchar(255) NOT NULL,
|
||
|
|
`referrer_host` varchar(255) NOT NULL DEFAULT '(direct)',
|
||
|
|
`ip_address` varchar(64) NOT NULL DEFAULT '',
|
||
|
|
`ip_hash` char(64) NOT NULL,
|
||
|
|
`user_agent` varchar(500) NOT NULL DEFAULT '',
|
||
|
|
`browser` varchar(32) NOT NULL DEFAULT 'Other',
|
||
|
|
`operating_system` varchar(32) NOT NULL DEFAULT 'Other',
|
||
|
|
`device_type` varchar(16) NOT NULL DEFAULT 'desktop',
|
||
|
|
`utm_source` varchar(100) NOT NULL DEFAULT '',
|
||
|
|
`utm_medium` varchar(100) NOT NULL DEFAULT '',
|
||
|
|
`utm_campaign` varchar(100) NOT NULL DEFAULT '',
|
||
|
|
`status_code` smallint(5) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`occurred_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`created_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
PRIMARY KEY (`id`),
|
||
|
|
UNIQUE KEY `uniq_site_visit_event_key` (`event_key`),
|
||
|
|
KEY `idx_site_visit_type_time` (`event_type`,`occurred_at`),
|
||
|
|
KEY `idx_site_visit_host_time` (`site_host`,`occurred_at`),
|
||
|
|
KEY `idx_site_visit_visitor_time` (`visitor_id`,`occurred_at`),
|
||
|
|
KEY `idx_site_visit_user_time` (`user_id`,`occurred_at`)
|
||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||
|
|
|
||
|
|
CREATE TABLE IF NOT EXISTS `site_visit_daily_stats` (
|
||
|
|
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||
|
|
`stat_date` date NOT NULL,
|
||
|
|
`event_type` varchar(16) NOT NULL,
|
||
|
|
`dimension_type` varchar(32) NOT NULL,
|
||
|
|
`dimension_value` varchar(255) NOT NULL,
|
||
|
|
`event_count` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`unique_visitors` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`created_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`updated_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
PRIMARY KEY (`id`),
|
||
|
|
UNIQUE KEY `uniq_site_visit_daily_dimension` (`stat_date`,`event_type`,`dimension_type`,`dimension_value`),
|
||
|
|
KEY `idx_site_visit_daily_lookup` (`event_type`,`dimension_type`,`stat_date`),
|
||
|
|
KEY `idx_site_visit_daily_value` (`dimension_type`,`dimension_value`,`stat_date`)
|
||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||
|
|
|
||
|
|
CREATE TABLE IF NOT EXISTS `site_security_events` (
|
||
|
|
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||
|
|
`event_key` char(64) NOT NULL,
|
||
|
|
`user_id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`visitor_id` char(32) NOT NULL,
|
||
|
|
`session_id` char(32) NOT NULL,
|
||
|
|
`site_host` varchar(255) NOT NULL,
|
||
|
|
`request_path` varchar(500) NOT NULL,
|
||
|
|
`request_method` varchar(12) NOT NULL,
|
||
|
|
`status_code` smallint(5) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`reason_code` varchar(32) NOT NULL,
|
||
|
|
`risk_level` varchar(16) NOT NULL,
|
||
|
|
`ip_address` varchar(64) NOT NULL DEFAULT '',
|
||
|
|
`ip_hash` char(64) NOT NULL,
|
||
|
|
`user_agent` varchar(500) NOT NULL DEFAULT '',
|
||
|
|
`browser` varchar(32) NOT NULL DEFAULT 'Other',
|
||
|
|
`operating_system` varchar(32) NOT NULL DEFAULT 'Other',
|
||
|
|
`device_type` varchar(16) NOT NULL DEFAULT 'desktop',
|
||
|
|
`hit_count` int(10) UNSIGNED NOT NULL DEFAULT 1,
|
||
|
|
`first_seen_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`last_seen_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`created_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
`updated_at` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
|
||
|
|
PRIMARY KEY (`id`),
|
||
|
|
UNIQUE KEY `uniq_site_security_event_key` (`event_key`),
|
||
|
|
KEY `idx_site_security_time_risk` (`last_seen_at`,`risk_level`),
|
||
|
|
KEY `idx_site_security_user_time` (`user_id`,`last_seen_at`),
|
||
|
|
KEY `idx_site_security_ip_time` (`ip_hash`,`last_seen_at`),
|
||
|
|
KEY `idx_site_security_reason_time` (`reason_code`,`last_seen_at`),
|
||
|
|
KEY `idx_site_security_status_time` (`status_code`,`last_seen_at`)
|
||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|