create_waf_tables.sql 3.07 KB
Newer Older
qiuqunfeng's avatar
commit  
qiuqunfeng committed
1 2
-- Create waf_services table
CREATE TABLE waf_services (
3
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
qiuqunfeng's avatar
commit  
qiuqunfeng committed
4 5 6 7 8 9
    gateway_name VARCHAR(255) NOT NULL,
    namespace VARCHAR(255) NOT NULL,
    region_code VARCHAR(50) NOT NULL,
    mode VARCHAR(50) NOT NULL,
    rule_num INTEGER DEFAULT 0,
    attack_num INTEGER DEFAULT 0,
qiuqunfeng's avatar
qiuqunfeng committed
10
    rule_category_status JSON,
qiuqunfeng's avatar
commit  
qiuqunfeng committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
);

-- Create waf_rules table
CREATE TABLE waf_rules (
    id SERIAL PRIMARY KEY,
    category_id VARCHAR(255) NOT NULL,
    level INTEGER NOT NULL,
    name VARCHAR(255) NOT NULL,
    type VARCHAR(50) NOT NULL,
    description TEXT,
    expr TEXT NOT NULL,
    mode VARCHAR(50) NOT NULL
);

-- Create waf_rule_categories table
CREATE TABLE waf_rule_categories (
27
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
qiuqunfeng's avatar
commit  
qiuqunfeng committed
28 29 30 31 32 33
    category_id VARCHAR(255) NOT NULL,
    category_en VARCHAR(255) NOT NULL,
    category_zh VARCHAR(255) NOT NULL,
    description_en TEXT,
    description_zh TEXT,
    status INTEGER NOT NULL,
qiuqunfeng's avatar
qiuqunfeng committed
34
    rules JSON NOT NULL
qiuqunfeng's avatar
commit  
qiuqunfeng committed
35 36
);

37
-- Create gateway_listeners table
38 39 40 41 42 43 44 45 46 47
-- CREATE TABLE gateway_listeners (
--     id SERIAL PRIMARY KEY,
--     gateway_name VARCHAR(255) NOT NULL,
--     namespace VARCHAR(255) NOT NULL,
--     region_code VARCHAR(50) NOT NULL,
--     port INTEGER NOT NULL,
--     enable BOOLEAN NOT NULL,
--     hosts TEXT
-- );

qiuqunfeng's avatar
debug  
qiuqunfeng committed
48
-- Create waf_listener_histories table
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
CREATE TABLE `waf_listener_histories` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `name` varchar(255) DEFAULT NULL,
    `gateway_name` varchar(255) DEFAULT NULL,
    `listener_name` varchar(255) DEFAULT NULL,
    `namespace` varchar(255) DEFAULT NULL,
    `region_code` varchar(255) DEFAULT NULL,
    `description` text DEFAULT NULL,
    `status` int DEFAULT NULL,
    `operation` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

qiuqunfeng's avatar
debug  
qiuqunfeng committed
64
-- Create waf_blackwhitelists table
65 66 67 68 69 70 71 72 73 74 75 76
CREATE TABLE IF NOT EXISTS waf_blackwhitelists
(
    id               bigint       NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name             varchar(128) NOT NULL,
    scope            varchar(256) NOT NULL,
    mode             varchar(32),
    expr             varchar(512),
    status           smallint     NOT NULL,
    global           boolean              DEFAULT false,
    created_at       timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at       timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY (name)
77 78
);

qiuqunfeng's avatar
commit  
qiuqunfeng committed
79 80 81 82
-- Add indexes for better query performance
CREATE INDEX idx_waf_services_gateway_name ON waf_services(gateway_name);
CREATE INDEX idx_waf_services_namespace ON waf_services(namespace);
CREATE INDEX idx_waf_rules_category_id ON waf_rules(category_id);
83 84 85 86
CREATE INDEX idx_waf_rule_categories_category_id ON waf_rule_categories(category_id);
CREATE INDEX idx_gateway_listeners_gateway_name ON gateway_listeners(gateway_name);
CREATE INDEX idx_gateway_listeners_namespace ON gateway_listeners(namespace);
CREATE INDEX idx_gateway_listeners_region_code ON gateway_listeners(region_code);