From 73f3d582863a36d8b1b382eb3ae84729f47c199e Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sat, 28 Feb 2026 15:52:30 +0800 Subject: [PATCH] add sql --- policy.sql | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 policy.sql diff --git a/policy.sql b/policy.sql new file mode 100644 index 0000000..dcf44f1 --- /dev/null +++ b/policy.sql @@ -0,0 +1,46 @@ +CREATE TABLE `identity` ( + `identity_id` int NOT NULL AUTO_INCREMENT, + `network_id` int NOT NULL, + `subject_type` enum('token','instance','user','service') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `subject_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `created_at` int NOT NULL DEFAULT '0', + `expired_at` int NOT NULL DEFAULT '0', + PRIMARY KEY (`identity_id`), + UNIQUE KEY `uk_subject` (`network_id`,`subject_type`,`subject_id`), + KEY `idx_network_id` (`network_id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + + +CREATE TABLE `identity_policy` ( + `identity_id` int NOT NULL, + `policy_id` int NOT NULL, + PRIMARY KEY (`identity_id`,`policy_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + + +CREATE TABLE `policy` ( + `policy_id` int NOT NULL AUTO_INCREMENT, + `network_id` int NOT NULL, + `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `created_at` int NOT NULL DEFAULT '0', + PRIMARY KEY (`policy_id`), + KEY `idx_network_id` (`network_id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + +CREATE TABLE `rule` ( + `rule_id` int NOT NULL AUTO_INCREMENT, + `policy_id` int NOT NULL, + `network_id` int NOT NULL, + `access_rule_id` int NOT NULL, + `src_policy_id` int NOT NULL, + `dst_policy_id` int NOT NULL, + `proto` tinyint NOT NULL, + `port` int NOT NULL, + `action` enum('allow','deny') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `created_at` int NOT NULL DEFAULT '0', + PRIMARY KEY (`rule_id`), + KEY `idx_src` (`src_policy_id`), + KEY `idx_network_id` (`network_id`), + KEY `idx_dst` (`dst_policy_id`) +) ENGINE=InnoDB AUTO_INCREMENT=85 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci \ No newline at end of file