This commit is contained in:
Ember Moth
2026-07-05 22:35:53 +08:00
parent 4ffdc89421
commit 5de9508963
83 changed files with 33 additions and 1033 deletions
+1
View File
@@ -2,3 +2,4 @@
AGENTS.md AGENTS.md
LOGGING_DESIGN.md LOGGING_DESIGN.md
MIGRATION_STRATEGY.md MIGRATION_STRATEGY.md
config-rust.yaml
+12 -15
View File
@@ -9,35 +9,22 @@
**PPanel 服务端的 Rust 重写版本 — 基于 Axum + sqlx,同时支持 MySQL / MariaDB 和 PostgreSQL。** **PPanel 服务端的 Rust 重写版本 — 基于 Axum + sqlx,同时支持 MySQL / MariaDB 和 PostgreSQL。**
[中文](README.md) | [报告问题](https://github.com/perfect-panel/ppanel-backend/issues/new)
</div> </div>
> **第一条**
> 人人生而自由,在尊严与权利上一律平等。
> 他们赋有理性与良知,应当以兄弟般的精神彼此相待。
>
> **第十九条**
> 人人有思想与表达的自由;此项自由包括持有主张而不受干预,以及通过任何媒介、无论国界,自由寻求、接受和传播信息与思想。
>
> *来源:[United Nations Universal Declaration of Human Rights](https://www.un.org/sites/un2.un.org/files/2021/03/udhr.pdf)*
--- ---
## 📋 概述 ## 📋 概述
`ppanel-backend` 是 [PPanel 服务端 (Go)](https://github.com/perfect-panel/server) 的 Rust 移植版本,使用 **Axum 0.8 + sqlx 0.9 + Tokio** 构建,与 Go 版本保持完整的 API 兼容性。 `ppanel-backend` 是 [PPanel 服务端 (Go)](https://github.com/perfect-panel/backend) 的 Rust 移植版本,使用 **Axum 0.8 + sqlx 0.9 + Tokio** 构建,与 Go 版本保持完整的 API 兼容性。
### 与 Go 版本的差异与改进 ### 与 Go 版本的差异与改进
| 维度 | Go 版 | Rust 版 | | 维度 | Go 版 | Rust 版 |
|---|---|---| |---|---|---|
| HTTP 框架 | go-zero / Hertz | Axum 0.8 | | HTTP 框架 | Hertz | Axum 0.8 |
| ORM | GORM | sqlx 0.9(编译期 SQL 检查) | | ORM | GORM | sqlx 0.9(编译期 SQL 检查) |
| 数据库 | MySQL 为主 | MySQL / MariaDB + PostgreSQL 双后端 |
| 异步运行时 | goroutine | Tokio | | 异步运行时 | goroutine | Tokio |
| 内存安全 | GC | 所有权系统,无 GC 暂停 | | 内存安全 | GC | 所有权系统,无 GC 暂停 |
| 插件系统 | WebAssembly | 暂不实现 |
### 核心特性 ### 核心特性
@@ -245,3 +232,13 @@ Trace:
## 📄 许可证 ## 📄 许可证
本项目采用 [Apache License 2.0](LICENSE) 授权。 本项目采用 [Apache License 2.0](LICENSE) 授权。
## Star History
<a href="https://www.star-history.com/?type=date&repos=perfect-panel%2Fppanel-backend">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=perfect-panel/ppanel-backend&type=date&theme=dark&legend=top-left" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=perfect-panel/ppanel-backend&type=date&legend=top-left" />
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=perfect-panel/ppanel-backend&type=date&legend=top-left" />
</picture>
</a>
-39
View File
@@ -1,5 +1,3 @@
-- migrate:up
-- 000001_init_schema.up.sql
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
CREATE TABLE IF NOT EXISTS `ads` CREATE TABLE IF NOT EXISTS `ads`
@@ -555,40 +553,3 @@ CREATE TABLE IF NOT EXISTS `server_rule_group`
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
-- migrate:down
-- 000001_init_schema.down.sql
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `user_subscribe_log`;
DROP TABLE IF EXISTS `user_subscribe`;
DROP TABLE IF EXISTS `user_login_log`;
DROP TABLE IF EXISTS `user_gift_amount_log`;
DROP TABLE IF EXISTS `user_device`;
DROP TABLE IF EXISTS `user_commission_log`;
DROP TABLE IF EXISTS `user_balance_log`;
DROP TABLE IF EXISTS `user_auth_methods`;
DROP TABLE IF EXISTS `user`;
DROP TABLE IF EXISTS `traffic_log`;
DROP TABLE IF EXISTS `ticket_follow`;
DROP TABLE IF EXISTS `ticket`;
DROP TABLE IF EXISTS `system`;
DROP TABLE IF EXISTS `subscribe_type`;
DROP TABLE IF EXISTS `subscribe_group`;
DROP TABLE IF EXISTS `subscribe`;
DROP TABLE IF EXISTS `sms`;
DROP TABLE IF EXISTS `server_rule_group`;
DROP TABLE IF EXISTS `server_group`;
DROP TABLE IF EXISTS `server`;
DROP TABLE IF EXISTS `payment`;
DROP TABLE IF EXISTS `order`;
DROP TABLE IF EXISTS `message_log`;
DROP TABLE IF EXISTS `document`;
DROP TABLE IF EXISTS `coupon`;
DROP TABLE IF EXISTS `auth_method`;
DROP TABLE IF EXISTS `application_version`;
DROP TABLE IF EXISTS `application_config`;
DROP TABLE IF EXISTS `application`;
DROP TABLE IF EXISTS `announcement`;
DROP TABLE IF EXISTS `ads`;
SET FOREIGN_KEY_CHECKS = 1;
@@ -1,5 +1,3 @@
-- migrate:up
-- 000002_init_data.up.sql
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
-- auth_method -- auth_method
@@ -126,25 +124,3 @@ VALUES (1, 'site', 'SiteLogo', '/favicon.svg', 'string', 'Site Logo', '2025-04-2
(41, 'system', 'Version', '0.2.0(02002)', 'string', 'System Version', '2025-04-22 14:25:16.642', (41, 'system', 'Version', '0.2.0(02002)', 'string', 'System Version', '2025-04-22 14:25:16.642',
'2025-04-22 14:25:16.642'); '2025-04-22 14:25:16.642');
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
-- migrate:down
-- 000002_init_data.down.sql
SET
FOREIGN_KEY_CHECKS = 0;
DELETE
FROM `auth_method`
WHERE `id` IN (1, 2, 3, 4, 5, 6, 7, 8);
DELETE
FROM `payment`
WHERE `id` = -1;
DELETE
FROM `subscribe_type`
WHERE `id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
DELETE
FROM `system`
WHERE `id` IN
(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);
SET
FOREIGN_KEY_CHECKS = 1;
-74
View File
@@ -1,4 +1,3 @@
-- migrate:up
-- 2025-04-22 16:16:00 -- 2025-04-22 16:16:00
-- Purpose: Update payment table -- Purpose: Update payment table
-- Author: PPanel Team, 2025-04-21 -- Author: PPanel Team, 2025-04-21
@@ -71,76 +70,3 @@ EXECUTE stmt;
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
-- migrate:down
-- migrations/02003_update_payment.down.sql
-- Purpose: Revert updates to payment and order tables
-- Author: PPanel Team, 2025-04-21
SET FOREIGN_KEY_CHECKS = 0;
-- Drop payment_id column from order table (if exists)
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'order'
AND COLUMN_NAME = 'payment_id');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `order` DROP COLUMN `payment_id`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop platform column from payment table (if exists)
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'payment'
AND COLUMN_NAME = 'platform');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `payment` DROP COLUMN `platform`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop description column from payment table (if exists)
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'payment'
AND COLUMN_NAME = 'description');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `payment` DROP COLUMN `description`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Drop token column from payment table (if exists)
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'payment'
AND COLUMN_NAME = 'token');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `payment` DROP COLUMN `token`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Optionally restore mark column (if needed, adjust definition as per original schema)
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'payment'
AND COLUMN_NAME = 'mark');
SET @sql = IF(@column_exists = 0,
'ALTER TABLE `payment` ADD COLUMN `mark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT \'Payment Mark\' AFTER `name`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;
-6
View File
@@ -1,4 +1,3 @@
-- migrate:up
-- migrations/02003_rebuild_rule.up.sql -- migrations/02003_rebuild_rule.up.sql
-- Purpose: rebuilding server rule table -- Purpose: rebuilding server rule table
-- Author: PPanel Team, 2025-04-21 -- Author: PPanel Team, 2025-04-21
@@ -21,8 +20,3 @@ CREATE TABLE `server_rule_group`
) ENGINE = InnoDB ) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci; COLLATE = utf8mb4_general_ci;
-- migrate:down
-- migrations/02003_rebuild_rule.up.sql
-- Purpose: Back rebuilding server rule table
-- Author: PPanel Team, 2025-04-21
DROP TABLE IF EXISTS server_rule_group;
@@ -1,4 +1,3 @@
-- migrate:up
-- migrations/02005_create_user_device_online_record.up.sql -- migrations/02005_create_user_device_online_record.up.sql
-- Purpose: Create table for tracking user device online records -- Purpose: Create table for tracking user device online records
-- Author: PPanel Team, 2025-04-22 -- Author: PPanel Team, 2025-04-22
@@ -69,56 +68,3 @@ PREPARE stmt FROM @sql;
EXECUTE stmt; EXECUTE stmt;
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
-- migrate:down
-- migrations/02004_create_user_device_online_record.down.sql
-- Purpose: Drop user device online record table
-- Author: PPanel Team, 2025-04-22
DROP TABLE IF EXISTS `user_device_online_record`;
-- User subscribe table migration for removing finished_at column
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'user_subscribe'
AND COLUMN_NAME = 'finished_at');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `user_subscribe` DROP COLUMN `finished_at`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Application config table migration for removing invitation_link column
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'application_config'
AND COLUMN_NAME = 'invitation_link');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `application_config` DROP COLUMN `invitation_link`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Application config table migration for removing kr_website_id column
SET @column_exists = (SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'application_config'
AND COLUMN_NAME = 'kr_website_id');
SET @sql = IF(@column_exists > 0,
'ALTER TABLE `application_config` DROP COLUMN `kr_website_id`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
@@ -1,4 +1,3 @@
-- migrate:up
-- migrations/02008_create_user_reset_subscribe_log.up.sql -- migrations/02008_create_user_reset_subscribe_log.up.sql
-- Purpose: Create user_reset_subscribe_log table -- Purpose: Create user_reset_subscribe_log table
-- Author: PPanel Team, 2025-04-22 -- Author: PPanel Team, 2025-04-22
@@ -17,10 +16,3 @@ CREATE TABLE IF NOT EXISTS `user_reset_subscribe_log`
DEFAULT CHARSET = utf8mb4 DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci; COLLATE = utf8mb4_general_ci;
-- migrate:down
-- migrations/02008_create_user_reset_subscribe_log.down.sql
-- Purpose: Drop user_reset_subscribe_log table
-- Author: PPanel Team, 2025-04-22
DROP TABLE IF EXISTS `user_reset_subscribe_log`;
-6
View File
@@ -1,9 +1,3 @@
-- migrate:up
ALTER TABLE `server_rule_group` ALTER TABLE `server_rule_group`
ADD COLUMN `default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is Default Group', ADD COLUMN `default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is Default Group',
ADD COLUMN `type` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'Rule Group Type'; ADD COLUMN `type` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'Rule Group Type';
-- migrate:down
ALTER TABLE `server_rule_group`
DROP COLUMN `default`,
DROP COLUMN `type`;
-3
View File
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS `email_task`; DROP TABLE IF EXISTS `email_task`;
CREATE TABLE `email_task` ( CREATE TABLE `email_task` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
@@ -23,5 +22,3 @@ CREATE TABLE `email_task` (
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
-- migrate:down
DROP TABLE IF EXISTS `email_task`;
File diff suppressed because one or more lines are too long
@@ -1,7 +1,4 @@
-- migrate:up
INSERT IGNORE INTO `system` (`id`, `category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) INSERT IGNORE INTO `system` (`id`, `category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
VALUES VALUES
(42, 'subscribe', 'UserAgentLimit', 'false', 'bool', 'User Agent Limit', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'), (42, 'subscribe', 'UserAgentLimit', 'false', 'bool', 'User Agent Limit', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'),
(43, 'subscribe', 'UserAgentList', '', 'string', 'User Agent List', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'); (43, 'subscribe', 'UserAgentList', '', 'string', 'User Agent List', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637');
-- migrate:down
@@ -1,6 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS `application`; DROP TABLE IF EXISTS `application`;
DROP TABLE IF EXISTS `application_version`; DROP TABLE IF EXISTS `application_version`;
DROP TABLE IF EXISTS `application_config`; DROP TABLE IF EXISTS `application_config`;
-- migrate:down
-108
View File
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS `user_balance_log`; DROP TABLE IF EXISTS `user_balance_log`;
DROP TABLE IF EXISTS `user_commission_log`; DROP TABLE IF EXISTS `user_commission_log`;
DROP TABLE IF EXISTS `user_gift_amount_log`; DROP TABLE IF EXISTS `user_gift_amount_log`;
@@ -18,110 +17,3 @@ CREATE TABLE `system_logs` (
KEY `idx_type` (`type`), KEY `idx_type` (`type`),
KEY `idx_object_id` (`object_id`) KEY `idx_object_id` (`object_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- migrate:down
CREATE TABLE IF NOT EXISTS `user_balance_log`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL COMMENT 'User ID',
`amount` bigint NOT NULL COMMENT 'Amount',
`type` tinyint(1) NOT NULL COMMENT 'Type: 1: Recharge 2: Withdraw 3: Payment 4: Refund 5: Reward',
`order_id` bigint DEFAULT NULL COMMENT 'Order ID',
`balance` bigint NOT NULL COMMENT 'Balance',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `user_commission_log`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL COMMENT 'User ID',
`order_no` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'Order No.',
`amount` bigint NOT NULL COMMENT 'Amount',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `user_gift_amount_log`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL COMMENT 'User ID',
`user_subscribe_id` bigint DEFAULT NULL COMMENT 'Deduction User Subscribe ID',
`order_no` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'Order No.',
`type` tinyint(1) NOT NULL COMMENT 'Type: 1: Increase 2: Reduce',
`amount` bigint NOT NULL COMMENT 'Amount',
`balance` bigint NOT NULL COMMENT 'Balance',
`remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT 'Remark',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `user_login_log`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL COMMENT 'User ID',
`login_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Login IP',
`user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'UserAgent',
`success` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Login Success',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `user_reset_subscribe_log`
(
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` BIGINT NOT NULL COMMENT 'User ID',
`type` TINYINT(1) NOT NULL COMMENT 'Type: 1: Auto 2: Advance 3: Paid',
`order_no` VARCHAR(255) DEFAULT NULL COMMENT 'Order No.',
`user_subscribe_id` BIGINT NOT NULL COMMENT 'User Subscribe ID',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation Time',
INDEX `idx_user_id` (`user_id`),
INDEX `idx_user_subscribe_id` (`user_subscribe_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `user_subscribe_log`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL COMMENT 'User ID',
`user_subscribe_id` bigint NOT NULL COMMENT 'User Subscribe ID',
`token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Token',
`ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'IP',
`user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'UserAgent',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_user_subscribe_id` (`user_subscribe_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `message_log`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'email' COMMENT 'Message Type',
`platform` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'smtp' COMMENT 'Platform',
`to` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'To',
`subject` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Subject',
`content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT 'Content',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Status',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Create Time',
`updated_at` datetime(3) DEFAULT NULL COMMENT 'Update Time',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
DROP TABLE IF EXISTS `system_logs`;
-5
View File
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS `servers` ( CREATE TABLE IF NOT EXISTS `servers` (
`id` bigint NOT NULL AUTO_INCREMENT, `id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Server Name', `name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Server Name',
@@ -28,7 +27,3 @@ CREATE TABLE IF NOT EXISTS `nodes` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- migrate:down
DROP TABLE IF EXISTS `nodes`;
DROP TABLE IF EXISTS `servers`;
-8
View File
@@ -1,4 +1,3 @@
-- migrate:up
ALTER TABLE `subscribe` ALTER TABLE `subscribe`
ADD COLUMN `nodes` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Node IDs', ADD COLUMN `nodes` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Node IDs',
ADD COLUMN `node_tags` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Node Tags', ADD COLUMN `node_tags` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Node Tags',
@@ -7,10 +6,3 @@ DROP COLUMN `server_group`;
DROP TABLE IF EXISTS `server_rule_group`; DROP TABLE IF EXISTS `server_rule_group`;
-- migrate:down
ALTER TABLE `subscribe`
DROP COLUMN `nodes`,
DROP COLUMN `node_tags`,
ADD COLUMN `server` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Server',
ADD COLUMN `server_group` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Server Group';
-3
View File
@@ -1,7 +1,4 @@
-- migrate:up
INSERT IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) INSERT IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
VALUES VALUES
('log', 'AutoClear', 'true', 'bool', 'Auto Clear Log', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'), ('log', 'AutoClear', 'true', 'bool', 'Auto Clear Log', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'),
('log', 'ClearDays', '7', 'int', 'Clear Days', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'); ('log', 'ClearDays', '7', 'int', 'Clear Days', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637');
-- migrate:down
-5
View File
@@ -1,4 +1,3 @@
-- migrate:up
ALTER TABLE `user` ALTER TABLE `user`
ADD COLUMN `referral_percentage` TINYINT UNSIGNED NOT NULL DEFAULT 0 ADD COLUMN `referral_percentage` TINYINT UNSIGNED NOT NULL DEFAULT 0
COMMENT 'Referral Percentage' COMMENT 'Referral Percentage'
@@ -7,7 +6,3 @@ ALTER TABLE `user`
COMMENT 'Only First Purchase' COMMENT 'Only First Purchase'
AFTER `referral_percentage`; AFTER `referral_percentage`;
-- migrate:down
ALTER TABLE `user`
DROP COLUMN `referral_percentage`,
DROP COLUMN `only_first_purchase`;
-4
View File
@@ -1,7 +1,3 @@
-- migrate:up
ALTER TABLE `nodes` ALTER TABLE `nodes`
ADD COLUMN `sort` INT UNSIGNED NOT NULL DEFAULT 0 ADD COLUMN `sort` INT UNSIGNED NOT NULL DEFAULT 0
COMMENT 'Sort' AFTER `enabled`; COMMENT 'Sort' AFTER `enabled`;
-- migrate:down
ALTER TABLE `nodes`
DROP COLUMN `sort`;
@@ -1,6 +1,2 @@
-- migrate:up
CREATE INDEX idx_traffic_log_time_user_sub ON traffic_log (timestamp, user_id, subscribe_id); CREATE INDEX idx_traffic_log_time_user_sub ON traffic_log (timestamp, user_id, subscribe_id);
-- migrate:down
DROP INDEX idx_traffic_log_time_user_sub ON traffic_log;
-4
View File
@@ -1,6 +1,2 @@
-- migrate:up
DROP TABLE IF EXISTS `subscribe_type`;
DROP TABLE IF EXISTS `sms`;
-- migrate:down
DROP TABLE IF EXISTS `subscribe_type`; DROP TABLE IF EXISTS `subscribe_type`;
DROP TABLE IF EXISTS `sms`; DROP TABLE IF EXISTS `sms`;
-3
View File
@@ -1,4 +1,3 @@
-- migrate:up
ALTER TABLE `subscribe` ALTER TABLE `subscribe`
DROP COLUMN `group_id`, DROP COLUMN `group_id`,
ADD COLUMN `language` VARCHAR(255) NOT NULL DEFAULT '' ADD COLUMN `language` VARCHAR(255) NOT NULL DEFAULT ''
@@ -6,5 +5,3 @@ ADD COLUMN `language` VARCHAR(255) NOT NULL DEFAULT ''
AFTER `name`; AFTER `name`;
DROP TABLE IF EXISTS `subscribe_group`; DROP TABLE IF EXISTS `subscribe_group`;
-- migrate:down
-3
View File
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS `email_task`; DROP TABLE IF EXISTS `email_task`;
CREATE TABLE `task` ( CREATE TABLE `task` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
@@ -13,5 +12,3 @@ CREATE TABLE `task` (
`updated_at` datetime(3) DEFAULT NULL COMMENT 'Update Time', `updated_at` datetime(3) DEFAULT NULL COMMENT 'Update Time',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- migrate:down
-3
View File
@@ -1,4 +1,3 @@
-- migrate:up
INSERT INSERT
IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
VALUE VALUE
@@ -7,5 +6,3 @@ VALUE
('server', 'DNS', '', 'string', 'DNS', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'), ('server', 'DNS', '', 'string', 'DNS', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'),
('server', 'Block', '', 'string', 'Block', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'), ('server', 'Block', '', 'string', 'Block', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'),
('server', 'Outbound', '', 'string', 'Proxy Outbound', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'); ('server', 'Outbound', '', 'string', 'Proxy Outbound', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637');
-- migrate:down
-3
View File
@@ -1,4 +1,3 @@
-- migrate:up
-- 只有当 ads 表中不存在 description 字段时才添加 -- 只有当 ads 表中不存在 description 字段时才添加
SET SET
@col_exists := ( @col_exists := (
@@ -20,5 +19,3 @@ PREPARE stmt FROM @query;
EXECUTE stmt; EXECUTE stmt;
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
-- migrate:down
-6
View File
@@ -1,4 +1,3 @@
-- migrate:up
-- 添加 algo 列(如果不存在) -- 添加 algo 列(如果不存在)
SET @dbname = DATABASE(); SET @dbname = DATABASE();
SET @tablename = 'user'; SET @tablename = 'user';
@@ -35,8 +34,3 @@ PREPARE stmt FROM @sql;
EXECUTE stmt; EXECUTE stmt;
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
-- migrate:down
ALTER TABLE `user`
DROP COLUMN `algo`,
DROP COLUMN `salt`;
@@ -1,13 +1,3 @@
-- migrate:up
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
SELECT 'site', 'CustomData', '{
"kr_website_id": ""
}', 'string', 'Custom Data', '2025-04-22 14:25:16.637', '2025-10-14 15:47:19.187'
WHERE NOT EXISTS (
SELECT 1 FROM `system` WHERE `category` = 'site' AND `key` = 'CustomData'
);
-- migrate:down
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
SELECT 'site', 'CustomData', '{ SELECT 'site', 'CustomData', '{
"kr_website_id": "" "kr_website_id": ""
@@ -1,6 +1,2 @@
-- migrate:up
ALTER TABLE traffic_log ADD INDEX idx_timestamp (timestamp); ALTER TABLE traffic_log ADD INDEX idx_timestamp (timestamp);
-- migrate:down
ALTER TABLE traffic_log DROP INDEX idx_timestamp;
@@ -1,10 +1,5 @@
-- migrate:up
ALTER TABLE `user_subscribe` ALTER TABLE `user_subscribe`
ADD COLUMN `note` VARCHAR(500) NOT NULL DEFAULT '' ADD COLUMN `note` VARCHAR(500) NOT NULL DEFAULT ''
COMMENT 'User note for subscription' COMMENT 'User note for subscription'
AFTER `status`; AFTER `status`;
-- migrate:down
ALTER TABLE `user_subscribe`
DROP COLUMN `note`;
-5
View File
@@ -1,10 +1,5 @@
-- migrate:up
ALTER TABLE `user` ALTER TABLE `user`
ADD COLUMN `rules` TEXT NULL ADD COLUMN `rules` TEXT NULL
COMMENT 'User rules for subscription' COMMENT 'User rules for subscription'
AFTER `created_at`; AFTER `created_at`;
-- migrate:down
ALTER TABLE `user`
DROP COLUMN IF EXISTS `rules`;
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS `withdrawals` ( CREATE TABLE IF NOT EXISTS `withdrawals` (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`user_id` BIGINT NOT NULL COMMENT 'User ID', `user_id` BIGINT NOT NULL COMMENT 'User ID',
@@ -15,10 +14,3 @@ CREATE TABLE IF NOT EXISTS `withdrawals` (
INSERT IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) INSERT IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
VALUES VALUES
('invite', 'WithdrawalMethod', '', 'string', 'withdrawal method', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'); ('invite', 'WithdrawalMethod', '', 'string', 'withdrawal method', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637');
-- migrate:down
DROP TABLE IF EXISTS `withdrawals`;
DELETE FROM `system`
WHERE `category` = 'invite'
AND `key` = 'WithdrawalMethod';
-30
View File
@@ -1,31 +1 @@
-- migrate:up
DROP TABLE IF EXISTS `server`; DROP TABLE IF EXISTS `server`;
-- migrate:down
CREATE TABLE IF NOT EXISTS `server`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Node Name',
`tags` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Tags',
`country` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Country',
`city` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'City',
`latitude` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'latitude',
`longitude` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'longitude',
`server_addr` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Server Address',
`relay_mode` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'none' COMMENT 'Relay Mode',
`relay_node` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT 'Relay Node',
`speed_limit` bigint NOT NULL DEFAULT '0' COMMENT 'Speed Limit',
`traffic_ratio` decimal(4, 2) NOT NULL DEFAULT '0.00' COMMENT 'Traffic Ratio',
`group_id` bigint DEFAULT NULL COMMENT 'Group ID',
`protocol` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Protocol',
`config` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT 'Config',
`enable` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Enabled',
`sort` bigint NOT NULL DEFAULT '0' COMMENT 'Sort',
`last_reported_at` datetime(3) DEFAULT NULL COMMENT 'Last Reported Time',
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
`updated_at` datetime(3) DEFAULT NULL COMMENT 'Update Time',
PRIMARY KEY (`id`),
KEY `idx_group_id` (`group_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;
@@ -1,8 +1,3 @@
-- migrate:up
ALTER TABLE `subscribe` ALTER TABLE `subscribe`
ADD COLUMN `show_original_price` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'display the original price: 0 not display, 1 display' AFTER `created_at`; ADD COLUMN `show_original_price` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'display the original price: 0 not display, 1 display' AFTER `created_at`;
-- migrate:down
ALTER TABLE `subscribe`
DROP COLUMN `show_original_price`;
@@ -1,4 +1 @@
-- migrate:up
DROP TABLE IF EXISTS `server_group`; DROP TABLE IF EXISTS `server_group`;
-- migrate:down
@@ -1,11 +1,4 @@
-- migrate:up
-- Update the `subscribe` table to set `inventory` to -1 where it is currently 0 -- Update the `subscribe` table to set `inventory` to -1 where it is currently 0
UPDATE `subscribe` UPDATE `subscribe`
SET `inventory` = -1 SET `inventory` = -1
WHERE `inventory` = 0; WHERE `inventory` = 0;
-- migrate:down
-- This migration script reverts the inventory values in the 'subscribe' table
UPDATE `subscribe`
SET `inventory` = 0
WHERE `inventory` = -1;
@@ -1,6 +1,2 @@
-- migrate:up
CREATE INDEX idx_type_date ON system_logs (type, date); CREATE INDEX idx_type_date ON system_logs (type, date);
-- migrate:down
DROP INDEX idx_type_date ON system_logs;
-134
View File
@@ -1,4 +1,3 @@
-- migrate:up
SET @index_exists = (SELECT COUNT(1) SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE() WHERE TABLE_SCHEMA = DATABASE()
@@ -131,136 +130,3 @@ PREPARE stmt FROM @sql;
EXECUTE stmt; EXECUTE stmt;
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
-- migrate:down
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'nodes'
AND INDEX_NAME = 'idx_nodes_port');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `nodes` DROP INDEX `idx_nodes_port`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'nodes'
AND INDEX_NAME = 'idx_nodes_tags');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `nodes` DROP INDEX `idx_nodes_tags`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'nodes'
AND INDEX_NAME = 'idx_nodes_address');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `nodes` DROP INDEX `idx_nodes_address`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'nodes'
AND INDEX_NAME = 'idx_nodes_name');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `nodes` DROP INDEX `idx_nodes_name`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'servers'
AND INDEX_NAME = 'idx_servers_address');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `servers` DROP INDEX `idx_servers_address`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'servers'
AND INDEX_NAME = 'idx_servers_name');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `servers` DROP INDEX `idx_servers_name`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'payment'
AND INDEX_NAME = 'idx_payment_name');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `payment` DROP INDEX `idx_payment_name`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'coupon'
AND INDEX_NAME = 'idx_coupon_name');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `coupon` DROP INDEX `idx_coupon_name`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'user'
AND INDEX_NAME = 'idx_user_refer_code');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `user` DROP INDEX `idx_user_refer_code`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'order'
AND INDEX_NAME = 'idx_order_coupon');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `order` DROP INDEX `idx_order_coupon`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @index_exists = (SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'order'
AND INDEX_NAME = 'idx_order_trade_no');
SET @sql = IF(@index_exists > 0,
'ALTER TABLE `order` DROP INDEX `idx_order_trade_no`',
'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS `server_config_overrides` CREATE TABLE IF NOT EXISTS `server_config_overrides`
( (
`id` bigint NOT NULL AUTO_INCREMENT, `id` bigint NOT NULL AUTO_INCREMENT,
@@ -15,6 +14,3 @@ CREATE TABLE IF NOT EXISTS `server_config_overrides`
DEFAULT CHARSET = utf8mb4 DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci; COLLATE = utf8mb4_general_ci;
-- migrate:down
DROP TABLE IF EXISTS `server_config_overrides`;
-20
View File
@@ -1,4 +1,3 @@
-- migrate:up
SET @column_exists = ( SET @column_exists = (
SELECT COUNT(*) SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS FROM INFORMATION_SCHEMA.COLUMNS
@@ -21,22 +20,3 @@ UPDATE `payment`
SET `sort` = `id` SET `sort` = `id`
WHERE `sort` = 0; WHERE `sort` = 0;
-- migrate:down
SET @column_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'payment'
AND COLUMN_NAME = 'sort'
);
SET @sql = IF(
@column_exists > 0,
'ALTER TABLE `payment` DROP COLUMN `sort`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
@@ -1,10 +1,6 @@
-- migrate:up
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
SELECT 'subscribe', 'ShowTutorial', 'true', 'bool', 'Show tutorial section on the user document page', '2025-04-22 14:25:16.639', '2025-04-22 14:25:16.639' SELECT 'subscribe', 'ShowTutorial', 'true', 'bool', 'Show tutorial section on the user document page', '2025-04-22 14:25:16.639', '2025-04-22 14:25:16.639'
WHERE NOT EXISTS ( WHERE NOT EXISTS (
SELECT 1 FROM `system` WHERE `category` = 'subscribe' AND `key` = 'ShowTutorial' SELECT 1 FROM `system` WHERE `category` = 'subscribe' AND `key` = 'ShowTutorial'
); );
-- migrate:down
DELETE FROM `system` WHERE `category` = 'subscribe' AND `key` = 'ShowTutorial';
@@ -1,9 +1,5 @@
-- migrate:up
-- MySQL datetime type does not have timezone support. -- MySQL datetime type does not have timezone support.
-- The Go code fix (serverPushStatusLogic.go, serverPushUserTrafficLogic.go) -- The Go code fix (serverPushStatusLogic.go, serverPushUserTrafficLogic.go)
-- removing .UTC() is sufficient for MySQL environments. -- removing .UTC() is sufficient for MySQL environments.
SELECT 1; SELECT 1;
-- migrate:down
SELECT 1;
+1 -37
View File
@@ -1,5 +1,3 @@
-- migrate:up
-- 000001_init_schema.up.sql
CREATE TABLE IF NOT EXISTS "ads" CREATE TABLE IF NOT EXISTS "ads"
( (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
@@ -307,7 +305,7 @@ CREATE INDEX IF NOT EXISTS "traffic_log_idx_user_id" ON "traffic_log" ("user_id"
CREATE TABLE IF NOT EXISTS "user" CREATE TABLE IF NOT EXISTS "user"
( (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"password" varchar(100) NOT NULL, "password" varchar(255) NOT NULL,
"avatar" text, "avatar" text,
"balance" bigint DEFAULT '0', "balance" bigint DEFAULT '0',
"telegram" bigint DEFAULT NULL, "telegram" bigint DEFAULT NULL,
@@ -458,37 +456,3 @@ CREATE TABLE IF NOT EXISTS "server_rule_group"
CONSTRAINT "unique_name" UNIQUE ("name") CONSTRAINT "unique_name" UNIQUE ("name")
); );
-- migrate:down
-- 000001_init_schema.down.sql
DROP TABLE IF EXISTS "user_subscribe_log";
DROP TABLE IF EXISTS "user_subscribe";
DROP TABLE IF EXISTS "user_login_log";
DROP TABLE IF EXISTS "user_gift_amount_log";
DROP TABLE IF EXISTS "user_device";
DROP TABLE IF EXISTS "user_commission_log";
DROP TABLE IF EXISTS "user_balance_log";
DROP TABLE IF EXISTS "user_auth_methods";
DROP TABLE IF EXISTS "user";
DROP TABLE IF EXISTS "traffic_log";
DROP TABLE IF EXISTS "ticket_follow";
DROP TABLE IF EXISTS "ticket";
DROP TABLE IF EXISTS "system";
DROP TABLE IF EXISTS "subscribe_type";
DROP TABLE IF EXISTS "subscribe_group";
DROP TABLE IF EXISTS "subscribe";
DROP TABLE IF EXISTS "sms";
DROP TABLE IF EXISTS "server_rule_group";
DROP TABLE IF EXISTS "server_group";
DROP TABLE IF EXISTS "server";
DROP TABLE IF EXISTS "payment";
DROP TABLE IF EXISTS "order";
DROP TABLE IF EXISTS "message_log";
DROP TABLE IF EXISTS "document";
DROP TABLE IF EXISTS "coupon";
DROP TABLE IF EXISTS "auth_method";
DROP TABLE IF EXISTS "application_version";
DROP TABLE IF EXISTS "application_config";
DROP TABLE IF EXISTS "application";
DROP TABLE IF EXISTS "announcement";
DROP TABLE IF EXISTS "ads";
@@ -1,5 +1,3 @@
-- migrate:up
-- 000002_init_data.up.sql
-- auth_method -- auth_method
INSERT INTO "auth_method" ("id", "method", "config", "enabled", "created_at", "updated_at") INSERT INTO "auth_method" ("id", "method", "config", "enabled", "created_at", "updated_at")
VALUES VALUES
@@ -116,20 +114,3 @@ SELECT setval(pg_get_serial_sequence('"auth_method"', 'id'), COALESCE((SELECT MA
SELECT setval(pg_get_serial_sequence('"subscribe_type"', 'id'), COALESCE((SELECT MAX("id") FROM "subscribe_type"), 1), true); SELECT setval(pg_get_serial_sequence('"subscribe_type"', 'id'), COALESCE((SELECT MAX("id") FROM "subscribe_type"), 1), true);
SELECT setval(pg_get_serial_sequence('"system"', 'id'), COALESCE((SELECT MAX("id") FROM "system"), 1), true); SELECT setval(pg_get_serial_sequence('"system"', 'id'), COALESCE((SELECT MAX("id") FROM "system"), 1), true);
-- migrate:down
-- 000002_init_data.down.sql
DELETE
FROM "auth_method"
WHERE "id" IN (1, 2, 3, 4, 5, 6, 7, 8);
DELETE
FROM "payment"
WHERE "id" = -1;
DELETE
FROM "subscribe_type"
WHERE "id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
DELETE
FROM "system"
WHERE "id" IN
(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);
@@ -1,4 +1,3 @@
-- migrate:up
-- PostgreSQL version of payment/order compatibility migration. -- PostgreSQL version of payment/order compatibility migration.
ALTER TABLE "order" ADD COLUMN IF NOT EXISTS "payment_id" BIGINT NOT NULL DEFAULT -1; ALTER TABLE "order" ADD COLUMN IF NOT EXISTS "payment_id" BIGINT NOT NULL DEFAULT -1;
ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "platform" VARCHAR(100) NOT NULL DEFAULT ''; ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "platform" VARCHAR(100) NOT NULL DEFAULT '';
@@ -6,10 +5,3 @@ ALTER TABLE "payment" DROP COLUMN IF EXISTS "mark";
ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "description" TEXT; ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "description" TEXT;
ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "token" VARCHAR(255) DEFAULT NULL; ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "token" VARCHAR(255) DEFAULT NULL;
-- migrate:down
ALTER TABLE "order" DROP COLUMN IF EXISTS "payment_id";
ALTER TABLE "payment" DROP COLUMN IF EXISTS "platform";
ALTER TABLE "payment" DROP COLUMN IF EXISTS "description";
ALTER TABLE "payment" DROP COLUMN IF EXISTS "token";
ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "mark" VARCHAR(255) DEFAULT NULL;
@@ -1,4 +1,3 @@
-- migrate:up
-- migrations/02003_rebuild_rule.up.sql -- migrations/02003_rebuild_rule.up.sql
-- Purpose: rebuilding server rule table -- Purpose: rebuilding server rule table
-- Author: PPanel Team, 2025-04-21 -- Author: PPanel Team, 2025-04-21
@@ -19,9 +18,3 @@ CREATE TABLE "server_rule_group"
); );
CREATE INDEX IF NOT EXISTS "server_rule_group_idx_enable" ON "server_rule_group" ("enable"); CREATE INDEX IF NOT EXISTS "server_rule_group_idx_enable" ON "server_rule_group" ("enable");
-- migrate:down
-- migrations/02003_rebuild_rule.up.sql
-- Purpose: Back rebuilding server rule table
-- Author: PPanel Team, 2025-04-21
DROP TABLE IF EXISTS server_rule_group;
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS "user_device_online_record" CREATE TABLE IF NOT EXISTS "user_device_online_record"
( (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
@@ -15,9 +14,3 @@ ALTER TABLE "user_subscribe" ADD COLUMN IF NOT EXISTS "finished_at" TIMESTAMP NU
ALTER TABLE "application_config" ADD COLUMN IF NOT EXISTS "invitation_link" TEXT NULL DEFAULT NULL; ALTER TABLE "application_config" ADD COLUMN IF NOT EXISTS "invitation_link" TEXT NULL DEFAULT NULL;
ALTER TABLE "application_config" ADD COLUMN IF NOT EXISTS "kr_website_id" VARCHAR(255) NULL DEFAULT NULL; ALTER TABLE "application_config" ADD COLUMN IF NOT EXISTS "kr_website_id" VARCHAR(255) NULL DEFAULT NULL;
-- migrate:down
DROP TABLE IF EXISTS "user_device_online_record";
ALTER TABLE "user_subscribe" DROP COLUMN IF EXISTS "finished_at";
ALTER TABLE "application_config" DROP COLUMN IF EXISTS "invitation_link";
ALTER TABLE "application_config" DROP COLUMN IF EXISTS "kr_website_id";
@@ -1,4 +1,3 @@
-- migrate:up
-- migrations/02008_create_user_reset_subscribe_log.up.sql -- migrations/02008_create_user_reset_subscribe_log.up.sql
-- Purpose: Create user_reset_subscribe_log table -- Purpose: Create user_reset_subscribe_log table
-- Author: PPanel Team, 2025-04-22 -- Author: PPanel Team, 2025-04-22
@@ -15,10 +14,3 @@ CREATE TABLE IF NOT EXISTS "user_reset_subscribe_log"
CREATE INDEX IF NOT EXISTS "user_reset_subscribe_log_idx_user_id" ON "user_reset_subscribe_log" ("user_id"); CREATE INDEX IF NOT EXISTS "user_reset_subscribe_log_idx_user_id" ON "user_reset_subscribe_log" ("user_id");
CREATE INDEX IF NOT EXISTS "user_reset_subscribe_log_idx_user_subscribe_id" ON "user_reset_subscribe_log" ("user_subscribe_id"); CREATE INDEX IF NOT EXISTS "user_reset_subscribe_log_idx_user_subscribe_id" ON "user_reset_subscribe_log" ("user_subscribe_id");
-- migrate:down
-- migrations/02008_create_user_reset_subscribe_log.down.sql
-- Purpose: Drop user_reset_subscribe_log table
-- Author: PPanel Team, 2025-04-22
DROP TABLE IF EXISTS "user_reset_subscribe_log";
@@ -1,10 +1,4 @@
-- migrate:up
ALTER TABLE "server_rule_group" ALTER TABLE "server_rule_group"
ADD COLUMN "default" BOOLEAN NOT NULL DEFAULT false, ADD COLUMN "default" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "type" VARCHAR(100) NOT NULL DEFAULT ''; ADD COLUMN "type" VARCHAR(100) NOT NULL DEFAULT '';
-- migrate:down
ALTER TABLE "server_rule_group"
DROP COLUMN "default",
DROP COLUMN "type";
-4
View File
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS "email_task"; DROP TABLE IF EXISTS "email_task";
CREATE TABLE "email_task" ( CREATE TABLE "email_task" (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
@@ -21,6 +20,3 @@ CREATE TABLE "email_task" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
); );
-- migrate:down
DROP TABLE IF EXISTS "email_task";
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS "subscribe_application"; DROP TABLE IF EXISTS "subscribe_application";
CREATE TABLE IF NOT EXISTS "subscribe_application" ( CREATE TABLE IF NOT EXISTS "subscribe_application" (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
@@ -32,6 +31,3 @@ INSERT INTO "subscribe_application" ("id", "name", "icon", "description", "schem
COMMIT; COMMIT;
SELECT setval(pg_get_serial_sequence('"subscribe_application"', 'id'), COALESCE((SELECT MAX("id") FROM "subscribe_application"), 1), true); SELECT setval(pg_get_serial_sequence('"subscribe_application"', 'id'), COALESCE((SELECT MAX("id") FROM "subscribe_application"), 1), true);
-- migrate:down
DROP TABLE IF EXISTS "subscribe_application";
@@ -1,9 +1,6 @@
-- migrate:up
INSERT INTO "system" ("id", "category", "key", "value", "type", "desc", "created_at", "updated_at") INSERT INTO "system" ("id", "category", "key", "value", "type", "desc", "created_at", "updated_at")
VALUES VALUES
(42, 'subscribe', 'UserAgentLimit', 'false', 'bool', 'User Agent Limit', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'), (42, 'subscribe', 'UserAgentLimit', 'false', 'bool', 'User Agent Limit', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'),
(43, 'subscribe', 'UserAgentList', '', 'string', 'User Agent List', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING; (43, 'subscribe', 'UserAgentList', '', 'string', 'User Agent List', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING;
SELECT setval(pg_get_serial_sequence('"system"', 'id'), COALESCE((SELECT MAX("id") FROM "system"), 1), true); SELECT setval(pg_get_serial_sequence('"system"', 'id'), COALESCE((SELECT MAX("id") FROM "system"), 1), true);
-- migrate:down
@@ -1,7 +1,4 @@
-- migrate:up
DROP TABLE IF EXISTS "application"; DROP TABLE IF EXISTS "application";
DROP TABLE IF EXISTS "application_version"; DROP TABLE IF EXISTS "application_version";
DROP TABLE IF EXISTS "application_config"; DROP TABLE IF EXISTS "application_config";
-- migrate:down
-88
View File
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS "user_balance_log"; DROP TABLE IF EXISTS "user_balance_log";
DROP TABLE IF EXISTS "user_commission_log"; DROP TABLE IF EXISTS "user_commission_log";
DROP TABLE IF EXISTS "user_gift_amount_log"; DROP TABLE IF EXISTS "user_gift_amount_log";
@@ -19,90 +18,3 @@ CREATE TABLE "system_logs" (
CREATE INDEX IF NOT EXISTS "system_logs_idx_type" ON "system_logs" ("type"); CREATE INDEX IF NOT EXISTS "system_logs_idx_type" ON "system_logs" ("type");
CREATE INDEX IF NOT EXISTS "system_logs_idx_object_id" ON "system_logs" ("object_id"); CREATE INDEX IF NOT EXISTS "system_logs_idx_object_id" ON "system_logs" ("object_id");
-- migrate:down
CREATE TABLE IF NOT EXISTS "user_balance_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"user_id" bigint NOT NULL,
"amount" bigint NOT NULL,
"type" SMALLINT NOT NULL,
"order_id" bigint DEFAULT NULL,
"balance" bigint NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX IF NOT EXISTS "user_balance_log_idx_user_id" ON "user_balance_log" ("user_id");
CREATE TABLE IF NOT EXISTS "user_commission_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"user_id" bigint NOT NULL,
"order_no" varchar(191) DEFAULT NULL,
"amount" bigint NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX IF NOT EXISTS "user_commission_log_idx_user_id" ON "user_commission_log" ("user_id");
CREATE TABLE IF NOT EXISTS "user_gift_amount_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"user_id" bigint NOT NULL,
"user_subscribe_id" bigint DEFAULT NULL,
"order_no" varchar(191) DEFAULT NULL,
"type" SMALLINT NOT NULL,
"amount" bigint NOT NULL,
"balance" bigint NOT NULL,
"remark" varchar(255) DEFAULT '',
"created_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX IF NOT EXISTS "user_gift_amount_log_idx_user_id" ON "user_gift_amount_log" ("user_id");
CREATE TABLE IF NOT EXISTS "user_login_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"user_id" bigint NOT NULL,
"login_ip" varchar(255) NOT NULL,
"user_agent" text NOT NULL,
"success" BOOLEAN NOT NULL DEFAULT false,
"created_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX IF NOT EXISTS "user_login_log_idx_user_id" ON "user_login_log" ("user_id");
CREATE TABLE IF NOT EXISTS "user_reset_subscribe_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
"user_id" BIGINT NOT NULL,
"type" SMALLINT NOT NULL,
"order_no" VARCHAR(255) DEFAULT NULL,
"user_subscribe_id" BIGINT NOT NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS "user_reset_subscribe_log_idx_user_id" ON "user_reset_subscribe_log" ("user_id");
CREATE INDEX IF NOT EXISTS "user_reset_subscribe_log_idx_user_subscribe_id" ON "user_reset_subscribe_log" ("user_subscribe_id");
CREATE TABLE IF NOT EXISTS "user_subscribe_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"user_id" bigint NOT NULL,
"user_subscribe_id" bigint NOT NULL,
"token" varchar(255) NOT NULL,
"ip" varchar(255) NOT NULL,
"user_agent" text NOT NULL,
"created_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX IF NOT EXISTS "user_subscribe_log_idx_user_id" ON "user_subscribe_log" ("user_id");
CREATE INDEX IF NOT EXISTS "user_subscribe_log_idx_user_subscribe_id" ON "user_subscribe_log" ("user_subscribe_id");
CREATE TABLE IF NOT EXISTS "message_log"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"type" varchar(50) NOT NULL DEFAULT 'email',
"platform" varchar(50) NOT NULL DEFAULT 'smtp',
"to" text NOT NULL,
"subject" varchar(255) NOT NULL DEFAULT '',
"content" text,
"status" SMALLINT NOT NULL DEFAULT '0',
"created_at" TIMESTAMP(3) DEFAULT NULL,
"updated_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
DROP TABLE IF EXISTS "system_logs";
-5
View File
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS "servers" ( CREATE TABLE IF NOT EXISTS "servers" (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"name" varchar(100) NOT NULL DEFAULT '', "name" varchar(100) NOT NULL DEFAULT '',
@@ -27,7 +26,3 @@ CREATE TABLE IF NOT EXISTS "nodes" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
); );
-- migrate:down
DROP TABLE IF EXISTS "nodes";
DROP TABLE IF EXISTS "servers";
-8
View File
@@ -1,4 +1,3 @@
-- migrate:up
ALTER TABLE "subscribe" ALTER TABLE "subscribe"
ADD COLUMN "nodes" VARCHAR(255) NOT NULL DEFAULT '' , ADD COLUMN "nodes" VARCHAR(255) NOT NULL DEFAULT '' ,
ADD COLUMN "node_tags" VARCHAR(255) NOT NULL DEFAULT '' , ADD COLUMN "node_tags" VARCHAR(255) NOT NULL DEFAULT '' ,
@@ -6,10 +5,3 @@ DROP COLUMN "server",
DROP COLUMN "server_group"; DROP COLUMN "server_group";
DROP TABLE IF EXISTS "server_rule_group"; DROP TABLE IF EXISTS "server_rule_group";
-- migrate:down
ALTER TABLE "subscribe"
DROP COLUMN "nodes",
DROP COLUMN "node_tags",
ADD COLUMN "server" VARCHAR(255) NOT NULL DEFAULT '' ,
ADD COLUMN "server_group" VARCHAR(255) NOT NULL DEFAULT '';
@@ -1,8 +1,5 @@
-- migrate:up
INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at") INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at")
VALUES VALUES
('log', 'AutoClear', 'true', 'bool', 'Auto Clear Log', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'), ('log', 'AutoClear', 'true', 'bool', 'Auto Clear Log', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637'),
('log', 'ClearDays', '7', 'int', 'Clear Days', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING; ('log', 'ClearDays', '7', 'int', 'Clear Days', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING;
-- migrate:down
@@ -1,10 +1,4 @@
-- migrate:up
ALTER TABLE "user" ALTER TABLE "user"
ADD COLUMN "referral_percentage" SMALLINT NOT NULL DEFAULT 0, ADD COLUMN "referral_percentage" SMALLINT NOT NULL DEFAULT 0,
ADD COLUMN "only_first_purchase" BOOLEAN NOT NULL DEFAULT true; ADD COLUMN "only_first_purchase" BOOLEAN NOT NULL DEFAULT true;
-- migrate:down
ALTER TABLE "user"
DROP COLUMN "referral_percentage",
DROP COLUMN "only_first_purchase";
-5
View File
@@ -1,8 +1,3 @@
-- migrate:up
ALTER TABLE "nodes" ALTER TABLE "nodes"
ADD COLUMN "sort" INTEGER NOT NULL DEFAULT 0; ADD COLUMN "sort" INTEGER NOT NULL DEFAULT 0;
-- migrate:down
ALTER TABLE "nodes"
DROP COLUMN "sort";
@@ -1,6 +1,2 @@
-- migrate:up
CREATE INDEX idx_traffic_log_time_user_sub ON traffic_log (timestamp, user_id, subscribe_id); CREATE INDEX idx_traffic_log_time_user_sub ON traffic_log (timestamp, user_id, subscribe_id);
-- migrate:down
DROP INDEX IF EXISTS "idx_traffic_log_time_user_sub";
@@ -1,8 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS "subscribe_type";
DROP TABLE IF EXISTS "sms";
-- migrate:down
DROP TABLE IF EXISTS "subscribe_type"; DROP TABLE IF EXISTS "subscribe_type";
DROP TABLE IF EXISTS "sms"; DROP TABLE IF EXISTS "sms";
-3
View File
@@ -1,8 +1,5 @@
-- migrate:up
ALTER TABLE "subscribe" ALTER TABLE "subscribe"
DROP COLUMN "group_id", DROP COLUMN "group_id",
ADD COLUMN "language" VARCHAR(255) NOT NULL DEFAULT ''; ADD COLUMN "language" VARCHAR(255) NOT NULL DEFAULT '';
DROP TABLE IF EXISTS "subscribe_group"; DROP TABLE IF EXISTS "subscribe_group";
-- migrate:down
-3
View File
@@ -1,4 +1,3 @@
-- migrate:up
DROP TABLE IF EXISTS "email_task"; DROP TABLE IF EXISTS "email_task";
CREATE TABLE "task" ( CREATE TABLE "task" (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
@@ -14,5 +13,3 @@ CREATE TABLE "task" (
PRIMARY KEY ("id") PRIMARY KEY ("id")
); );
-- migrate:down
@@ -1,4 +1,3 @@
-- migrate:up
INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at") INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at")
VALUES ('server', 'TrafficReportThreshold', '0', 'int', 'Traffic report threshold', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'), VALUES ('server', 'TrafficReportThreshold', '0', 'int', 'Traffic report threshold', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'),
('server', 'IPStrategy', '', 'string', 'IP Strategy', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'), ('server', 'IPStrategy', '', 'string', 'IP Strategy', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'),
@@ -6,5 +5,3 @@ VALUES ('server', 'TrafficReportThreshold', '0', 'int', 'Traffic report threshol
('server', 'Block', '', 'string', 'Block', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'), ('server', 'Block', '', 'string', 'Block', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637'),
('server', 'Outbound', '', 'string', 'Proxy Outbound', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING; ('server', 'Outbound', '', 'string', 'Proxy Outbound', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING;
-- migrate:down
-3
View File
@@ -1,5 +1,2 @@
-- migrate:up
ALTER TABLE "ads" ADD COLUMN IF NOT EXISTS "description" VARCHAR(255) DEFAULT ''; ALTER TABLE "ads" ADD COLUMN IF NOT EXISTS "description" VARCHAR(255) DEFAULT '';
-- migrate:down
-5
View File
@@ -1,8 +1,3 @@
-- migrate:up
ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "algo" VARCHAR(20) NOT NULL DEFAULT 'default'; ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "algo" VARCHAR(20) NOT NULL DEFAULT 'default';
ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "salt" VARCHAR(20) NOT NULL DEFAULT 'default'; ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "salt" VARCHAR(20) NOT NULL DEFAULT 'default';
-- migrate:down
ALTER TABLE "user" DROP COLUMN IF EXISTS "algo";
ALTER TABLE "user" DROP COLUMN IF EXISTS "salt";
@@ -1,13 +1,3 @@
-- migrate:up
INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at")
SELECT 'site', 'CustomData', '{
"kr_website_id": ""
}', 'string', 'Custom Data', '2025-04-22 14:25:16.637', '2025-10-14 15:47:19.187'
WHERE NOT EXISTS (
SELECT 1 FROM "system" WHERE "category" = 'site' AND "key" = 'CustomData'
);
-- migrate:down
INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at") INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at")
SELECT 'site', 'CustomData', '{ SELECT 'site', 'CustomData', '{
"kr_website_id": "" "kr_website_id": ""
@@ -1,6 +1,2 @@
-- migrate:up
CREATE INDEX IF NOT EXISTS "idx_timestamp" ON "traffic_log" ("timestamp"); CREATE INDEX IF NOT EXISTS "idx_timestamp" ON "traffic_log" ("timestamp");
-- migrate:down
DROP INDEX IF EXISTS "idx_timestamp";
@@ -1,8 +1,3 @@
-- migrate:up
ALTER TABLE "user_subscribe" ALTER TABLE "user_subscribe"
ADD COLUMN "note" VARCHAR(500) NOT NULL DEFAULT ''; ADD COLUMN "note" VARCHAR(500) NOT NULL DEFAULT '';
-- migrate:down
ALTER TABLE "user_subscribe"
DROP COLUMN "note";
-5
View File
@@ -1,8 +1,3 @@
-- migrate:up
ALTER TABLE "user" ALTER TABLE "user"
ADD COLUMN "rules" TEXT NULL; ADD COLUMN "rules" TEXT NULL;
-- migrate:down
ALTER TABLE "user"
DROP COLUMN IF EXISTS "rules";
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS "withdrawals" ( CREATE TABLE IF NOT EXISTS "withdrawals" (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"user_id" BIGINT NOT NULL, "user_id" BIGINT NOT NULL,
@@ -15,9 +14,3 @@ INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at",
VALUES VALUES
('invite', 'WithdrawalMethod', '', 'string', 'withdrawal method', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING; ('invite', 'WithdrawalMethod', '', 'string', 'withdrawal method', '2025-04-22 14:25:16.637', '2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING;
-- migrate:down
DROP TABLE IF EXISTS "withdrawals";
DELETE FROM "system"
WHERE "category" = 'invite'
AND "key" = 'WithdrawalMethod';
-28
View File
@@ -1,30 +1,2 @@
-- migrate:up
DROP TABLE IF EXISTS "server"; DROP TABLE IF EXISTS "server";
-- migrate:down
CREATE TABLE IF NOT EXISTS "server"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"name" varchar(100) NOT NULL DEFAULT '',
"tags" varchar(128) NOT NULL DEFAULT '',
"country" varchar(128) NOT NULL DEFAULT '',
"city" varchar(128) NOT NULL DEFAULT '',
"latitude" varchar(128) NOT NULL DEFAULT '',
"longitude" varchar(128) NOT NULL DEFAULT '',
"server_addr" varchar(100) NOT NULL DEFAULT '',
"relay_mode" varchar(20) NOT NULL DEFAULT 'none',
"relay_node" text,
"speed_limit" bigint NOT NULL DEFAULT '0',
"traffic_ratio" decimal(4, 2) NOT NULL DEFAULT '0.00',
"group_id" bigint DEFAULT NULL,
"protocol" varchar(20) NOT NULL DEFAULT '',
"config" text,
"enable" SMALLINT NOT NULL DEFAULT '1',
"sort" bigint NOT NULL DEFAULT '0',
"last_reported_at" TIMESTAMP(3) DEFAULT NULL,
"created_at" TIMESTAMP(3) DEFAULT NULL,
"updated_at" TIMESTAMP(3) DEFAULT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX IF NOT EXISTS "server_idx_group_id" ON "server" ("group_id");
@@ -1,8 +1,3 @@
-- migrate:up
ALTER TABLE "subscribe" ALTER TABLE "subscribe"
ADD COLUMN "show_original_price" BOOLEAN NOT NULL DEFAULT false; ADD COLUMN "show_original_price" BOOLEAN NOT NULL DEFAULT false;
-- migrate:down
ALTER TABLE "subscribe"
DROP COLUMN "show_original_price";
@@ -1,5 +1,2 @@
-- migrate:up
DROP TABLE IF EXISTS "server_group"; DROP TABLE IF EXISTS "server_group";
-- migrate:down
@@ -1,12 +1,5 @@
-- migrate:up
-- Update the "subscribe" table to set "inventory" to -1 where it is currently 0 -- Update the "subscribe" table to set "inventory" to -1 where it is currently 0
UPDATE "subscribe" UPDATE "subscribe"
SET "inventory" = -1 SET "inventory" = -1
WHERE "inventory" = 0; WHERE "inventory" = 0;
-- migrate:down
-- This migration script reverts the inventory values in the 'subscribe' table
UPDATE "subscribe"
SET "inventory" = 0
WHERE "inventory" = -1;
@@ -1,6 +1,2 @@
-- migrate:up
CREATE INDEX idx_type_date ON system_logs (type, date); CREATE INDEX idx_type_date ON system_logs (type, date);
-- migrate:down
DROP INDEX IF EXISTS "idx_type_date";
@@ -1,4 +1,3 @@
-- migrate:up
CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX IF NOT EXISTS "idx_order_order_no_pattern" ON "order" ("order_no" text_pattern_ops); CREATE INDEX IF NOT EXISTS "idx_order_order_no_pattern" ON "order" ("order_no" text_pattern_ops);
@@ -31,34 +30,3 @@ CREATE INDEX IF NOT EXISTS "idx_ticket_title_trgm" ON "ticket" USING GIN ("title
CREATE INDEX IF NOT EXISTS "idx_ticket_description_trgm" ON "ticket" USING GIN ("description" gin_trgm_ops); CREATE INDEX IF NOT EXISTS "idx_ticket_description_trgm" ON "ticket" USING GIN ("description" gin_trgm_ops);
CREATE INDEX IF NOT EXISTS "idx_system_logs_content_trgm" ON "system_logs" USING GIN ("content" gin_trgm_ops); CREATE INDEX IF NOT EXISTS "idx_system_logs_content_trgm" ON "system_logs" USING GIN ("content" gin_trgm_ops);
-- migrate:down
DROP INDEX IF EXISTS "idx_system_logs_content_trgm";
DROP INDEX IF EXISTS "idx_ticket_description_trgm";
DROP INDEX IF EXISTS "idx_ticket_title_trgm";
DROP INDEX IF EXISTS "idx_subscribe_description_trgm";
DROP INDEX IF EXISTS "idx_subscribe_name_trgm";
DROP INDEX IF EXISTS "idx_document_content_trgm";
DROP INDEX IF EXISTS "idx_document_title_trgm";
DROP INDEX IF EXISTS "idx_announcement_content_trgm";
DROP INDEX IF EXISTS "idx_announcement_title_trgm";
DROP INDEX IF EXISTS "idx_ads_content_trgm";
DROP INDEX IF EXISTS "idx_ads_title_trgm";
DROP INDEX IF EXISTS "idx_nodes_port";
DROP INDEX IF EXISTS "idx_nodes_tags_pattern";
DROP INDEX IF EXISTS "idx_nodes_address_pattern";
DROP INDEX IF EXISTS "idx_nodes_name_pattern";
DROP INDEX IF EXISTS "idx_servers_address_pattern";
DROP INDEX IF EXISTS "idx_servers_name_pattern";
DROP INDEX IF EXISTS "idx_payment_name_pattern";
DROP INDEX IF EXISTS "idx_coupon_code_pattern";
DROP INDEX IF EXISTS "idx_coupon_name_pattern";
DROP INDEX IF EXISTS "idx_user_auth_identifier_pattern";
DROP INDEX IF EXISTS "idx_user_refer_code_pattern";
DROP INDEX IF EXISTS "idx_order_coupon_pattern";
DROP INDEX IF EXISTS "idx_order_trade_no_pattern";
DROP INDEX IF EXISTS "idx_order_order_no_pattern";
@@ -1,4 +1,3 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS "server_config_overrides" CREATE TABLE IF NOT EXISTS "server_config_overrides"
( (
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
@@ -13,6 +12,3 @@ CREATE TABLE IF NOT EXISTS "server_config_overrides"
CONSTRAINT "uni_server_config_overrides_server_id" UNIQUE ("server_id") CONSTRAINT "uni_server_config_overrides_server_id" UNIQUE ("server_id")
); );
-- migrate:down
DROP TABLE IF EXISTS "server_config_overrides";
@@ -1,4 +1,3 @@
-- migrate:up
ALTER TABLE "payment" ALTER TABLE "payment"
ADD COLUMN IF NOT EXISTS "sort" bigint NOT NULL DEFAULT 0; ADD COLUMN IF NOT EXISTS "sort" bigint NOT NULL DEFAULT 0;
@@ -6,7 +5,3 @@ UPDATE "payment"
SET "sort" = "id" SET "sort" = "id"
WHERE "sort" = 0; WHERE "sort" = 0;
-- migrate:down
ALTER TABLE "payment"
DROP COLUMN IF EXISTS "sort";
@@ -1,10 +1,6 @@
-- migrate:up
INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at") INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at")
SELECT 'subscribe', 'ShowTutorial', 'true', 'bool', 'Show tutorial section on the user document page', '2025-04-22 14:25:16.639', '2025-04-22 14:25:16.639' SELECT 'subscribe', 'ShowTutorial', 'true', 'bool', 'Show tutorial section on the user document page', '2025-04-22 14:25:16.639', '2025-04-22 14:25:16.639'
WHERE NOT EXISTS ( WHERE NOT EXISTS (
SELECT 1 FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial' SELECT 1 FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial'
); );
-- migrate:down
DELETE FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial';
@@ -1,10 +1,4 @@
-- migrate:up
ALTER TABLE "servers" ALTER TABLE "servers"
ALTER COLUMN "last_reported_at" TYPE timestamptz ALTER COLUMN "last_reported_at" TYPE timestamptz
USING "last_reported_at" AT TIME ZONE 'UTC'; USING "last_reported_at" AT TIME ZONE 'UTC';
-- migrate:down
ALTER TABLE "servers"
ALTER COLUMN "last_reported_at" TYPE timestamp(3)
USING "last_reported_at" AT TIME ZONE 'UTC';
+1 -1
View File
@@ -324,7 +324,7 @@ pub fn register_routes(state: AppState) -> Router<()> {
.route("/v1/server/push", post(server_push_user_traffic)) .route("/v1/server/push", post(server_push_user_traffic))
.route("/v1/server/status", post(server_push_status)) .route("/v1/server/status", post(server_push_status))
.route("/v1/server/user", get(get_server_user_list)) .route("/v1/server/user", get(get_server_user_list))
.route("/v2/server/:server_id", get(query_server_protocol_config)) .route("/v2/server/{server_id}", get(query_server_protocol_config))
.route("/v1/subscribe/config", get(subscribe_handler)) .route("/v1/subscribe/config", get(subscribe_handler))
.route("/", get(pan_domain_subscribe_handler)) .route("/", get(pan_domain_subscribe_handler))
.route("/v1/telegram", post(telegram_handler)); .route("/v1/telegram", post(telegram_handler));
+14 -8
View File
@@ -14,7 +14,12 @@ mod mysql_migrations {
mod postgres_migrations { mod postgres_migrations {
#![allow(unused)] #![allow(unused)]
pub(super) const MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!("migrations/postgres"); pub(super) fn migrator() -> sqlx::migrate::Migrator {
let mut m = sqlx::migrate!("migrations/postgres");
m.set_locking(false);
m.no_tx = true;
m
}
} }
pub use crate::repository::Dialect; pub use crate::repository::Dialect;
@@ -24,7 +29,7 @@ use crate::repository::Db;
/// Run all pending migrations for the detected database dialect. /// Run all pending migrations for the detected database dialect.
pub async fn run_migrations(db: &Db) -> Result<(), sqlx::migrate::MigrateError> { pub async fn run_migrations(db: &Db) -> Result<(), sqlx::migrate::MigrateError> {
match db { match db {
Db::Postgres(pool) => postgres_migrations::MIGRATOR.run(pool).await, Db::Postgres(pool) => postgres_migrations::migrator().run(pool).await,
Db::Mysql(pool) => mysql_migrations::MIGRATOR.run(pool).await, Db::Mysql(pool) => mysql_migrations::MIGRATOR.run(pool).await,
} }
} }
@@ -60,6 +65,7 @@ async fn create_admin_user_pg(
} }
let now = chrono::Utc::now().timestamp_millis(); let now = chrono::Utc::now().timestamp_millis();
let now_ts = chrono::Utc::now(); // chrono::DateTime<Utc> -> PG timestamp
let password_hash = hash_password_pbkdf2(password); let password_hash = hash_password_pbkdf2(password);
let refer_code = generate_invite_code(); let refer_code = generate_invite_code();
@@ -68,12 +74,12 @@ async fn create_admin_user_pg(
gift_amount, enable, enable_balance_notify, gift_amount, enable, enable_balance_notify,
enable_login_notify, enable_subscribe_notify, enable_login_notify, enable_subscribe_notify,
enable_trade_notify, created_at, updated_at) enable_trade_notify, created_at, updated_at)
VALUES ($1, 'default', 1, $2, 0, 0, 0, 1, 1, 1, 1, 1, $3, $4)"#, VALUES ($1, 'default', TRUE, $2, 0, 0, 0, TRUE, TRUE, TRUE, TRUE, TRUE, $3, $4)"#,
) )
.bind(&password_hash) .bind(&password_hash)
.bind(&refer_code) .bind(&refer_code)
.bind(now) .bind(now_ts)
.bind(now) .bind(now_ts)
.execute(pool) .execute(pool)
.await .await
.map_err(|e| { .map_err(|e| {
@@ -93,12 +99,12 @@ async fn create_admin_user_pg(
sqlx::query( sqlx::query(
r#"INSERT INTO user_auth_methods (user_id, auth_type, auth_identifier, verified, created_at, updated_at) r#"INSERT INTO user_auth_methods (user_id, auth_type, auth_identifier, verified, created_at, updated_at)
VALUES ($1, 'email', $2, 1, $3, $4)"#, VALUES ($1, 'email', $2, TRUE, $3, $4)"#,
) )
.bind(user_id) .bind(user_id)
.bind(email) .bind(email)
.bind(now) .bind(now_ts)
.bind(now) .bind(now_ts)
.execute(pool) .execute(pool)
.await .await
.map_err(|e| { .map_err(|e| {
+4 -4
View File
@@ -38,7 +38,7 @@ impl Service {
Self::register( Self::register(
&scheduler, &scheduler,
types::SCHEDULER_CHECK_SUBSCRIPTION, types::SCHEDULER_CHECK_SUBSCRIPTION,
"@every 60s", "*/30 * * * * *",
"default", "default",
) )
.await?; .await?;
@@ -47,7 +47,7 @@ impl Service {
Self::register( Self::register(
&scheduler, &scheduler,
types::SCHEDULER_RESET_TRAFFIC, types::SCHEDULER_RESET_TRAFFIC,
"30 0 * * *", "0 30 0 * * *",
"default", "default",
) )
.await?; .await?;
@@ -56,7 +56,7 @@ impl Service {
Self::register( Self::register(
&scheduler, &scheduler,
types::SCHEDULER_TRAFFIC_STAT, types::SCHEDULER_TRAFFIC_STAT,
"0 0 * * *", "0 0 0 * * *",
"default", "default",
) )
.await?; .await?;
@@ -65,7 +65,7 @@ impl Service {
Self::register( Self::register(
&scheduler, &scheduler,
types::FORTHWITH_QUOTA_TASK, types::FORTHWITH_QUOTA_TASK,
"0 1 * * *", "0 0 1 * * *",
"default", "default",
) )
.await?; .await?;