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.
148 lines
6.2 KiB
SQL
148 lines
6.2 KiB
SQL
-- Virt Cloud: retained mail and website security/analytics log schema.
|
|
|
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
|
START TRANSACTION;
|
|
SET time_zone = "+00:00";
|
|
|
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
|
/*!40101 SET NAMES utf8mb4 */;
|
|
|
|
CREATE TABLE `setting` (
|
|
`id` bigint(20) NOT NULL,
|
|
`key` varchar(255) DEFAULT NULL,
|
|
`value:type:longtext` longtext DEFAULT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
|
|
CREATE TABLE `site_security_events` (
|
|
`id` bigint(20) UNSIGNED NOT NULL,
|
|
`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
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
|
|
CREATE TABLE `site_visit_daily_stats` (
|
|
`id` bigint(20) UNSIGNED NOT NULL,
|
|
`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
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
|
|
CREATE TABLE `site_visit_events` (
|
|
`id` bigint(20) UNSIGNED NOT NULL,
|
|
`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)',
|
|
`destination_host` varchar(255) NOT NULL DEFAULT '',
|
|
`redirect_slug` varchar(64) NOT NULL DEFAULT '',
|
|
`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
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
|
|
CREATE TABLE `user_email_log` (
|
|
`id` int(11) NOT NULL,
|
|
`email` varchar(254) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
|
|
`email_type` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
|
|
`status` tinyint(1) DEFAULT NULL COMMENT '1=成功, 0=失败, NULL=历史状态未知',
|
|
`request_domain` varchar(512) DEFAULT NULL,
|
|
`ip` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
|
|
`date` bigint(20) NOT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
|
|
ALTER TABLE `setting`
|
|
ADD PRIMARY KEY (`id`),
|
|
ADD UNIQUE KEY `idx_setting_nn_gmjp` (`key`),
|
|
ADD UNIQUE KEY `idx_setting_bzrhg9` (`key`),
|
|
ADD UNIQUE KEY `idx_setting_tl_c2dp_uw` (`key`),
|
|
ADD UNIQUE KEY `idx_setting_p_jq3lx_n_sq_ic_g` (`key`),
|
|
ADD UNIQUE KEY `idx_setting_if_q_hl_oq` (`key`),
|
|
ADD UNIQUE KEY `idx_setting_fjzl_y_zw_jd` (`key`),
|
|
ADD UNIQUE KEY `idx_setting_h7v_sb_mwfi0` (`key`);
|
|
|
|
ALTER TABLE `site_security_events`
|
|
ADD PRIMARY KEY (`id`),
|
|
ADD UNIQUE KEY `uniq_site_security_event_key` (`event_key`),
|
|
ADD KEY `idx_site_security_time_risk` (`last_seen_at`,`risk_level`),
|
|
ADD KEY `idx_site_security_user_time` (`user_id`,`last_seen_at`),
|
|
ADD KEY `idx_site_security_ip_time` (`ip_hash`,`last_seen_at`),
|
|
ADD KEY `idx_site_security_reason_time` (`reason_code`,`last_seen_at`),
|
|
ADD KEY `idx_site_security_status_time` (`status_code`,`last_seen_at`);
|
|
|
|
ALTER TABLE `site_visit_daily_stats`
|
|
ADD PRIMARY KEY (`id`),
|
|
ADD UNIQUE KEY `uniq_site_visit_daily_dimension` (`stat_date`,`event_type`,`dimension_type`,`dimension_value`),
|
|
ADD KEY `idx_site_visit_daily_lookup` (`event_type`,`dimension_type`,`stat_date`),
|
|
ADD KEY `idx_site_visit_daily_value` (`dimension_type`,`dimension_value`,`stat_date`);
|
|
|
|
ALTER TABLE `site_visit_events`
|
|
ADD PRIMARY KEY (`id`),
|
|
ADD UNIQUE KEY `uniq_site_visit_event_key` (`event_key`),
|
|
ADD KEY `idx_site_visit_type_time` (`event_type`,`occurred_at`),
|
|
ADD KEY `idx_site_visit_host_time` (`site_host`,`occurred_at`),
|
|
ADD KEY `idx_site_visit_visitor_time` (`visitor_id`,`occurred_at`),
|
|
ADD KEY `idx_site_visit_destination_time` (`destination_host`,`occurred_at`),
|
|
ADD KEY `idx_site_visit_user_time` (`user_id`,`occurred_at`);
|
|
|
|
ALTER TABLE `user_email_log`
|
|
ADD PRIMARY KEY (`id`);
|
|
|
|
ALTER TABLE `setting`
|
|
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
|
|
|
|
ALTER TABLE `site_security_events`
|
|
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
|
|
|
|
ALTER TABLE `site_visit_daily_stats`
|
|
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
|
|
|
|
ALTER TABLE `site_visit_events`
|
|
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
|
|
|
|
ALTER TABLE `user_email_log`
|
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
|
|
|
COMMIT;
|
|
|
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|