From 5de95089631e1b3a7da84de747deda15fcc9078d Mon Sep 17 00:00:00 2001 From: Ember Moth Date: Sun, 5 Jul 2026 22:35:53 +0800 Subject: [PATCH 1/2] fix bugs --- .gitignore | 1 + README.md | 27 ++-- migrations/mysql/00001_init_schema.sql | 39 ----- migrations/mysql/00002_init_basic_data.sql | 24 ---- migrations/mysql/02003_update_payment.sql | 74 ---------- migrations/mysql/02004_rebuild_rule.sql | 6 - .../mysql/02005_device_online_record.sql | 54 ------- .../mysql/02006_reset_subscribe_record.sql | 8 -- migrations/mysql/02007_adapte_rule.sql | 6 - migrations/mysql/02100_task.sql | 3 - .../mysql/02101_subscribe_application.sql | 3 - migrations/mysql/02102_subscribe_config.sql | 3 - migrations/mysql/02103_delete_application.sql | 3 - migrations/mysql/02104_system_log.sql | 108 -------------- migrations/mysql/02105_node.sql | 5 - migrations/mysql/02106_subscribe.sql | 8 -- migrations/mysql/02107_log_setting.sql | 3 - migrations/mysql/02108_user_referral.sql | 5 - migrations/mysql/02109_node_sort.sql | 4 - migrations/mysql/02110_traffic_log_index.sql | 4 - migrations/mysql/02111_clear_table.sql | 4 - migrations/mysql/02112_subscribe.sql | 3 - migrations/mysql/02113_task.sql | 3 - migrations/mysql/02114_node_config.sql | 3 - migrations/mysql/02115_ads.sql | 3 - migrations/mysql/02116_user_algo.sql | 6 - migrations/mysql/02117_site_custom_data.sql | 10 -- migrations/mysql/02118_traffic_log_idx.sql | 4 - .../mysql/02119_user_subscribe_note.sql | 5 - migrations/mysql/02120_user_rules.sql | 5 - migrations/mysql/02121_user_withdrawal.sql | 8 -- migrations/mysql/02122_server.sql | 30 ---- migrations/mysql/02123_subscribe_original.sql | 5 - .../mysql/02124_server_group_delete.sql | 3 - migrations/mysql/02125_subscribe_stock.sql | 7 - migrations/mysql/02126_system_log_idx.sql | 4 - migrations/mysql/02127_search_indexes.sql | 134 ------------------ .../mysql/02128_server_config_override.sql | 4 - migrations/mysql/02129_payment_sort.sql | 20 --- migrations/mysql/02130_subscribe_tutorial.sql | 4 - .../02131_timestamptz_last_reported_at.sql | 4 - migrations/postgres/00001_init_schema.sql | 38 +---- migrations/postgres/00002_init_basic_data.sql | 19 --- migrations/postgres/02003_update_payment.sql | 8 -- migrations/postgres/02004_rebuild_rule.sql | 7 - .../postgres/02005_device_online_record.sql | 7 - .../postgres/02006_reset_subscribe_record.sql | 8 -- migrations/postgres/02007_adapte_rule.sql | 6 - migrations/postgres/02100_task.sql | 4 - .../postgres/02101_subscribe_application.sql | 4 - .../postgres/02102_subscribe_config.sql | 3 - .../postgres/02103_delete_application.sql | 3 - migrations/postgres/02104_system_log.sql | 88 ------------ migrations/postgres/02105_node.sql | 5 - migrations/postgres/02106_subscribe.sql | 8 -- migrations/postgres/02107_log_setting.sql | 3 - migrations/postgres/02108_user_referral.sql | 6 - migrations/postgres/02109_node_sort.sql | 5 - .../postgres/02110_traffic_log_index.sql | 4 - migrations/postgres/02111_clear_table.sql | 5 - migrations/postgres/02112_subscribe.sql | 3 - migrations/postgres/02113_task.sql | 3 - migrations/postgres/02114_node_config.sql | 3 - migrations/postgres/02115_ads.sql | 3 - migrations/postgres/02116_user_algo.sql | 5 - .../postgres/02117_site_custom_data.sql | 10 -- migrations/postgres/02118_traffic_log_idx.sql | 4 - .../postgres/02119_user_subscribe_note.sql | 5 - migrations/postgres/02120_user_rules.sql | 5 - migrations/postgres/02121_user_withdrawal.sql | 7 - migrations/postgres/02122_server.sql | 28 ---- .../postgres/02123_subscribe_original.sql | 5 - .../postgres/02124_server_group_delete.sql | 3 - migrations/postgres/02125_subscribe_stock.sql | 7 - migrations/postgres/02126_system_log_idx.sql | 4 - migrations/postgres/02127_search_indexes.sql | 32 ----- .../postgres/02128_server_config_override.sql | 4 - migrations/postgres/02129_payment_sort.sql | 5 - .../postgres/02130_subscribe_tutorial.sql | 4 - .../02131_timestamptz_last_reported_at.sql | 6 - src/handler/routes.rs | 2 +- src/migration.rs | 22 +-- src/scheduler/mod.rs | 8 +- 83 files changed, 33 insertions(+), 1033 deletions(-) diff --git a/.gitignore b/.gitignore index 1f430c10..c3504b44 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ AGENTS.md LOGGING_DESIGN.md MIGRATION_STRATEGY.md +config-rust.yaml diff --git a/README.md b/README.md index e32de8cf..0ddd651d 100644 --- a/README.md +++ b/README.md @@ -9,35 +9,22 @@ **PPanel 服务端的 Rust 重写版本 — 基于 Axum + sqlx,同时支持 MySQL / MariaDB 和 PostgreSQL。** -[中文](README.md) | [报告问题](https://github.com/perfect-panel/ppanel-backend/issues/new) - -> **第一条** -> 人人生而自由,在尊严与权利上一律平等。 -> 他们赋有理性与良知,应当以兄弟般的精神彼此相待。 -> -> **第十九条** -> 人人有思想与表达的自由;此项自由包括持有主张而不受干预,以及通过任何媒介、无论国界,自由寻求、接受和传播信息与思想。 -> -> *来源:[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 版 | Rust 版 | |---|---|---| -| HTTP 框架 | go-zero / Hertz | Axum 0.8 | +| HTTP 框架 | Hertz | Axum 0.8 | | ORM | GORM | sqlx 0.9(编译期 SQL 检查) | -| 数据库 | MySQL 为主 | MySQL / MariaDB + PostgreSQL 双后端 | | 异步运行时 | goroutine | Tokio | | 内存安全 | GC | 所有权系统,无 GC 暂停 | -| 插件系统 | WebAssembly | 暂不实现 | ### 核心特性 @@ -245,3 +232,13 @@ Trace: ## 📄 许可证 本项目采用 [Apache License 2.0](LICENSE) 授权。 + +## Star History + + + + + + Star History Chart + + diff --git a/migrations/mysql/00001_init_schema.sql b/migrations/mysql/00001_init_schema.sql index a4a3eab5..61e66f0b 100644 --- a/migrations/mysql/00001_init_schema.sql +++ b/migrations/mysql/00001_init_schema.sql @@ -1,5 +1,3 @@ --- migrate:up --- 000001_init_schema.up.sql SET FOREIGN_KEY_CHECKS = 0; CREATE TABLE IF NOT EXISTS `ads` @@ -555,40 +553,3 @@ CREATE TABLE IF NOT EXISTS `server_rule_group` 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; diff --git a/migrations/mysql/00002_init_basic_data.sql b/migrations/mysql/00002_init_basic_data.sql index 5f267716..cc6beaa4 100644 --- a/migrations/mysql/00002_init_basic_data.sql +++ b/migrations/mysql/00002_init_basic_data.sql @@ -1,5 +1,3 @@ --- migrate:up --- 000002_init_data.up.sql SET FOREIGN_KEY_CHECKS = 0; -- 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', '2025-04-22 14:25:16.642'); 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; diff --git a/migrations/mysql/02003_update_payment.sql b/migrations/mysql/02003_update_payment.sql index c81b2aa0..13cf72eb 100644 --- a/migrations/mysql/02003_update_payment.sql +++ b/migrations/mysql/02003_update_payment.sql @@ -1,4 +1,3 @@ --- migrate:up -- 2025-04-22 16:16:00 -- Purpose: Update payment table -- Author: PPanel Team, 2025-04-21 @@ -71,76 +70,3 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; 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; diff --git a/migrations/mysql/02004_rebuild_rule.sql b/migrations/mysql/02004_rebuild_rule.sql index 2d2c5d45..be3ead31 100644 --- a/migrations/mysql/02004_rebuild_rule.sql +++ b/migrations/mysql/02004_rebuild_rule.sql @@ -1,4 +1,3 @@ --- migrate:up -- migrations/02003_rebuild_rule.up.sql -- Purpose: rebuilding server rule table -- Author: PPanel Team, 2025-04-21 @@ -21,8 +20,3 @@ CREATE TABLE `server_rule_group` ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 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; diff --git a/migrations/mysql/02005_device_online_record.sql b/migrations/mysql/02005_device_online_record.sql index 2e2d61f3..0d71dbff 100644 --- a/migrations/mysql/02005_device_online_record.sql +++ b/migrations/mysql/02005_device_online_record.sql @@ -1,4 +1,3 @@ --- migrate:up -- migrations/02005_create_user_device_online_record.up.sql -- Purpose: Create table for tracking user device online records -- Author: PPanel Team, 2025-04-22 @@ -69,56 +68,3 @@ PREPARE stmt FROM @sql; EXECUTE 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; diff --git a/migrations/mysql/02006_reset_subscribe_record.sql b/migrations/mysql/02006_reset_subscribe_record.sql index cbf89311..53e1d32b 100644 --- a/migrations/mysql/02006_reset_subscribe_record.sql +++ b/migrations/mysql/02006_reset_subscribe_record.sql @@ -1,4 +1,3 @@ --- migrate:up -- migrations/02008_create_user_reset_subscribe_log.up.sql -- Purpose: Create user_reset_subscribe_log table -- Author: PPanel Team, 2025-04-22 @@ -17,10 +16,3 @@ CREATE TABLE IF NOT EXISTS `user_reset_subscribe_log` DEFAULT CHARSET = utf8mb4 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`; - diff --git a/migrations/mysql/02007_adapte_rule.sql b/migrations/mysql/02007_adapte_rule.sql index 32e22700..dd2010d6 100644 --- a/migrations/mysql/02007_adapte_rule.sql +++ b/migrations/mysql/02007_adapte_rule.sql @@ -1,9 +1,3 @@ --- migrate:up ALTER TABLE `server_rule_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'; --- migrate:down -ALTER TABLE `server_rule_group` -DROP COLUMN `default`, -DROP COLUMN `type`; - diff --git a/migrations/mysql/02100_task.sql b/migrations/mysql/02100_task.sql index 6a89211b..8b4b2d74 100644 --- a/migrations/mysql/02100_task.sql +++ b/migrations/mysql/02100_task.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS `email_task`; CREATE TABLE `email_task` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', @@ -23,5 +22,3 @@ CREATE TABLE `email_task` ( SET FOREIGN_KEY_CHECKS = 1; --- migrate:down -DROP TABLE IF EXISTS `email_task`; diff --git a/migrations/mysql/02101_subscribe_application.sql b/migrations/mysql/02101_subscribe_application.sql index be8c4d5a..e4a53899 100644 --- a/migrations/mysql/02101_subscribe_application.sql +++ b/migrations/mysql/02101_subscribe_application.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS `subscribe_application`; CREATE TABLE IF NOT EXISTS `subscribe_application` ( `id` bigint NOT NULL AUTO_INCREMENT, @@ -27,5 +26,3 @@ INSERT INTO `subscribe_application` (`id`, `name`, `icon`, `description`, `schem INSERT INTO `subscribe_application` (`id`, `name`, `icon`, `description`, `scheme`, `user_agent`, `is_default`, `subscribe_template`, `output_format`, `download_link`, `created_at`, `updated_at`) VALUES (5, 'Surge', '', '', 'surge:///install-config?url=${encodeURIComponent(url)}', 'Surge', 0, '{{- $GiB := 1073741824.0 -}}\n{{- $used := printf \"%.2f\" (divf (add (.UserInfo.Download | default 0 | float64) (.UserInfo.Upload | default 0 | float64)) $GiB) -}}\n{{- $traffic := (.UserInfo.Traffic | default 0 | float64) -}}\n{{- $total := printf \"%.2f\" (divf $traffic $GiB) -}}\n\n{{- $ExpiredAt := \"\" -}}\n{{- $expStr := printf \"%v\" .UserInfo.ExpiredAt -}}\n{{- if regexMatch `^[0-9]+$` $expStr -}}\n {{- $ts := $expStr | float64 -}}\n {{- $sec := ternary (divf $ts 1000.0) $ts (ge (len $expStr) 13) -}}\n {{- $ExpiredAt = (date \"2006-01-02 15:04:05\" (unixEpoch ($sec | int64))) -}}\n{{- else -}}\n {{- $ExpiredAt = $expStr -}}\n{{- end -}}\n\n{{- $sortFields := list \"Sort\" \"Port\" \"Name\" -}}\n{{- $sortConfig := dict \"Sort\" \"asc\" \"Port\" \"asc\" \"Name\" \"asc\" -}}\n{{- $byKey := dict -}}\n{{- range $p := .Proxies -}}\n {{- $keyParts := list -}}\n {{- range $field := $sortFields -}}\n {{- $order := index $sortConfig $field -}}\n {{- $val := default \"\" (printf \"%v\" (index $p $field)) -}}\n {{- if or (eq $field \"Sort\") (eq $field \"Port\") -}}\n {{- $val = printf \"%08d\" (int (default 0 (index $p $field))) -}}\n {{- end -}}\n {{- if eq $order \"desc\" -}}\n {{- $val = printf \"~%s\" $val -}}\n {{- end -}}\n {{- $keyParts = append $keyParts $val -}}\n {{- end -}}\n {{- $_ := set $byKey (join \"|\" $keyParts) $p -}}\n{{- end -}}\n{{- $sorted := list -}}\n{{- range $k := sortAlpha (keys $byKey) -}}\n {{- $sorted = append $sorted (index $byKey $k) -}}\n{{- end -}}\n\n{{- $supportSet := dict \"shadowsocks\" true \"vmess\" true \"vless\" true \"trojan\" true \"hysteria2\" true \"hysteria\" true \"tuic\" true \"wireguard\" true -}}\n{{- $supportedProxies := list -}}\n{{- range $proxy := $sorted -}}\n {{- if hasKey $supportSet $proxy.Type -}}\n {{- $supportedProxies = append $supportedProxies $proxy -}}\n {{- end -}}\n{{- end -}}\n\n{{- $proxyNames := \"\" -}}\n{{- range $proxy := $supportedProxies -}}\n {{- if eq $proxyNames \"\" -}}\n {{- $proxyNames = $proxy.Name -}}\n {{- else -}}\n {{- $proxyNames = printf \"%s, %s\" $proxyNames $proxy.Name -}}\n {{- end -}}\n{{- end -}}\n\n# {{ .SiteName }}-{{ .SubscribeName }}\n# Traffic: {{ $used }} GiB/{{ $total }} GiB | Expires: {{ $ExpiredAt }}\n# Generated at: {{ now | date \"2006-01-02 15:04:05\" }}\n\n#!MANAGED-CONFIG {{ .UserInfo.SubscribeURL }} interval=86400 strict=true\n\n[General]\n# 日志级别\nloglevel = notify\n\n# 外部控制器访问\nexternal-controller-access = perlnk@0.0.0.0:6170\n\n# 网络设置\nexclude-simple-hostnames = true\nshow-error-page-for-reject = true\nudp-priority = true\nudp-policy-not-supported-behaviour = reject\nipv6 = true\nipv6-vif = auto\n\n# 连接测试\nproxy-test-url = http://www.gstatic.com/generate_204\ninternet-test-url = http://www.gstatic.com/generate_204\ntest-timeout = 5\n\n# DNS 设置\ndns-server = system, 119.29.29.29, 223.5.5.5\nencrypted-dns-server = https://dns.alidns.com/dns-query\nhijack-dns = 8.8.8.8:53, 8.8.4.4:53, 1.1.1.1:53, 1.0.0.1:53\n\n# 跳过代理\nskip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 127.0.0.0/8, localhost, *.local\n\n# 真实 IP\nalways-real-ip = *.lan, lens.l.google.com, *.srv.nintendo.net, *.stun.playstation.net, *.xboxlive.com, xbox.*.*.microsoft.com, *.msftncsi.com, *.msftconnecttest.com\n\n# Surge Mac 参数\nhttp-listen = 0.0.0.0:6088\nsocks5-listen = 0.0.0.0:6089\n\n# Surge iOS 参数(WiFi 共享)\nallow-wifi-access = true\nallow-hotspot-access = true\nwifi-access-http-port = 6088\nwifi-access-socks5-port = 6089\n\n[Panel]\nSubscribeInfo = title={{ .SiteName }} - {{ .SubscribeName }}, content=已用流量: {{ $used }} GiB/{{ $total }} GiB \\n到期时间: {{ $ExpiredAt}}, style=info\n\n[Proxy]\n{{- range $proxy := $supportedProxies }}\n {{- $common := \"udp-relay=true, tfo=true\" -}}\n\n {{- $server := $proxy.Server -}}\n {{- if and (contains $server \":\") (not (hasPrefix \"[\" $server)) -}}\n {{- $server = printf \"[%s]\" $server -}}\n {{- end -}}\n\n {{- $password := $.UserInfo.Password -}}\n {{- if and (eq $proxy.Type \"shadowsocks\") (ne (default \"\" $proxy.ServerKey) \"\") -}}\n {{- $method := $proxy.Method -}}\n {{- if or (hasPrefix \"2022-blake3-\" $method) (eq $method \"2022-blake3-aes-128-gcm\") (eq $method \"2022-blake3-aes-256-gcm\") -}}\n {{- $userKeyLen := ternary 16 32 (hasSuffix \"128-gcm\" $method) -}}\n {{- $pwdStr := printf \"%s\" $password -}}\n {{- $userKey := ternary $pwdStr (trunc $userKeyLen $pwdStr) (le (len $pwdStr) $userKeyLen) -}}\n {{- $serverB64 := b64enc $proxy.ServerKey -}}\n {{- $userB64 := b64enc $userKey -}}\n {{- $password = printf \"%s:%s\" $serverB64 $userB64 -}}\n {{- end -}}\n {{- end -}}\n\n {{- $SkipVerify := $proxy.AllowInsecure -}}\n\n {{- if eq $proxy.Type \"shadowsocks\" }}\n{{ $proxy.Name }} = ss, {{ $server }}, {{ $proxy.Port }}, encrypt-method={{ default \"aes-128-gcm\" $proxy.Method }}, password={{ $password }}{{- if ne (default \"\" $proxy.Obfs) \"\" }}, obfs={{ $proxy.Obfs }}{{- if ne (default \"\" $proxy.ObfsHost) \"\" }}, obfs-host={{ $proxy.ObfsHost }}{{- end }}{{- end }}, {{ $common }}\n {{- else if eq $proxy.Type \"vmess\" }}\n{{ $proxy.Name }} = vmess, {{ $server }}, {{ $proxy.Port }}, username={{ $password }}{{- if or (eq $proxy.Transport \"ws\") (eq $proxy.Transport \"websocket\") }}, ws=true{{- if ne (default \"\" $proxy.Path) \"\" }}, ws-path={{ $proxy.Path }}{{- end }}{{- if ne (default \"\" $proxy.Host) \"\" }}, ws-headers=\"Host:{{ $proxy.Host }}\"{{- end }}{{- else if eq $proxy.Transport \"grpc\" }}, grpc=true{{- if ne (default \"\" $proxy.ServiceName) \"\" }}, grpc-service-name={{ $proxy.ServiceName }}{{- end }}{{- end }}{{- if or (eq $proxy.Security \"tls\") (eq $proxy.Security \"reality\") }}, tls=true{{- end }}{{- if ne (default \"\" $proxy.SNI) \"\" }}, sni={{ $proxy.SNI }}{{- end }}{{- if $proxy.AllowInsecure }}, skip-cert-verify=true{{- end }}{{- if ne (default \"\" $proxy.Fingerprint) \"\" }}, fingerprint={{ $proxy.Fingerprint }}{{- end }}, {{ $common }}\n {{- else if eq $proxy.Type \"vless\" }}\n{{ $proxy.Name }} = vless, {{ $server }}, {{ $proxy.Port }}, username={{ $password }}{{- if or (eq $proxy.Transport \"ws\") (eq $proxy.Transport \"websocket\") }}, ws=true{{- if ne (default \"\" $proxy.Path) \"\" }}, ws-path={{ $proxy.Path }}{{- end }}{{- if ne (default \"\" $proxy.Host) \"\" }}, ws-headers=\"Host:{{ $proxy.Host }}\"{{- end }}{{- else if eq $proxy.Transport \"grpc\" }}, grpc=true{{- if ne (default \"\" $proxy.ServiceName) \"\" }}, grpc-service-name={{ $proxy.ServiceName }}{{- end }}{{- end }}{{- if ne (default \"\" $proxy.SNI) \"\" }}, sni={{ $proxy.SNI }}{{- end }}{{- if $proxy.AllowInsecure }}, skip-cert-verify=true{{- end }}{{- if ne (default \"\" $proxy.Flow) \"none\" }}, flow={{ $proxy.Flow }}{{- end }}, {{ $common }}\n {{- else if eq $proxy.Type \"trojan\" }}\n{{ $proxy.Name }} = trojan, {{ $server }}, {{ $proxy.Port }}, password={{ $password }}{{- if or (eq $proxy.Transport \"ws\") (eq $proxy.Transport \"websocket\") }}, ws=true{{- if ne (default \"\" $proxy.Path) \"\" }}, ws-path={{ $proxy.Path }}{{- end }}{{- if ne (default \"\" $proxy.Host) \"\" }}, ws-headers=\"Host:{{ $proxy.Host }}\"{{- end }}{{- else if eq $proxy.Transport \"grpc\" }}, grpc=true{{- if ne (default \"\" $proxy.ServiceName) \"\" }}, grpc-service-name={{ $proxy.ServiceName }}{{- end }}{{- end }}{{- if ne (default \"\" $proxy.SNI) \"\" }}, sni={{ $proxy.SNI }}{{- end }}{{- if $proxy.AllowInsecure }}, skip-cert-verify=true{{- end }}{{- if ne (default \"\" $proxy.Fingerprint) \"\" }}, fingerprint={{ $proxy.Fingerprint }}{{- end }}, {{ $common }}\n {{- else if or (eq $proxy.Type \"hysteria2\") (eq $proxy.Type \"hysteria\") }}\n{{ $proxy.Name }} = hysteria2, {{ $server }}, {{ $proxy.Port }}, password={{ $password }}{{- if ne (default \"\" $proxy.SNI) \"\" }}, sni={{ $proxy.SNI }}{{- end }}{{- if $proxy.AllowInsecure }}, skip-cert-verify=true{{- end }}{{- if ne (default \"\" $proxy.ObfsPassword) \"\" }}, obfs=salamander, obfs-password={{ $proxy.ObfsPassword }}{{- end }}{{- if ne (default \"\" $proxy.HopPorts) \"\" }}, ports={{ $proxy.HopPorts }}{{- end }}{{- if ne (default 0 $proxy.HopInterval) 0 }}, hop-interval={{ $proxy.HopInterval }}{{- end }}, {{ $common }}\n {{- else if eq $proxy.Type \"tuic\" }}\n{{ $proxy.Name }} = tuic, {{ $server }}, {{ $proxy.Port }}, uuid={{ default \"\" $proxy.ServerKey }}, password={{ $password }}{{- if ne (default \"\" $proxy.SNI) \"\" }}, sni={{ $proxy.SNI }}{{- end }}{{- if $proxy.AllowInsecure }}, skip-cert-verify=true{{- end }}{{- if $proxy.DisableSNI }}, disable-sni=true{{- end }}{{- if $proxy.ReduceRtt }}, reduce-rtt=true{{- end }}{{- if ne (default \"\" $proxy.UDPRelayMode) \"\" }}, udp-relay-mode={{ $proxy.UDPRelayMode }}{{- end }}{{- if ne (default \"\" $proxy.CongestionController) \"\" }}, congestion-controller={{ $proxy.CongestionController }}{{- end }}, {{ $common }}\n {{- else if eq $proxy.Type \"wireguard\" }}\n{{ $proxy.Name }} = wireguard, {{ $server }}, {{ $proxy.Port }}, private-key={{ default \"\" $proxy.ServerKey }}, public-key={{ default \"\" $proxy.RealityPublicKey }}{{- if ne (default \"\" $proxy.Path) \"\" }}, preshared-key={{ $proxy.Path }}{{- end }}{{- if ne (default \"\" $proxy.RealityServerAddr) \"\" }}, ip={{ $proxy.RealityServerAddr }}{{- end }}{{- if ne (default 0 $proxy.RealityServerPort) 0 }}, ipv6={{ $proxy.RealityServerPort }}{{- end }}, {{ $common }}\n {{- else if eq $proxy.Type \"anytls\" }}\n{{ $proxy.Name }} = anytls, {{ $server }}, {{ $proxy.Port }}, password={{ $password }}{{- if ne (default \"\" $proxy.SNI) \"\" }}, sni={{ $proxy.SNI }}{{- end }}{{- if $proxy.AllowInsecure }}, skip-cert-verify=true{{- end }}, {{ $common }}\n {{- else }}\n{{ $proxy.Name }} = {{ $proxy.Type }}, {{ $server }}, {{ $proxy.Port }}, {{ $common }}\n {{- end }}\n{{- end }}\n\n[Proxy Group]\n# 主要策略组\n🚀 Proxy = select, 🌏 Auto, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🍎 Apple = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🔍 Google = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🪟 Microsoft = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n📺 GlobalMedia = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🤖 AI = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🪙 Crypto = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🎮 Game = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n📟 Telegram = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n🇨🇳 China = select, 🎯 Direct, 🚀 Proxy, include-other-group=🇺🇳 Nodes\n🐠 Final = select, 🚀 Proxy, 🎯 Direct, include-other-group=🇺🇳 Nodes\n\n# 智能选择和节点组\n🌏 Auto = smart, include-other-group=🇺🇳 Nodes\n🎯 Direct = select, DIRECT, hidden=1\n🇺🇳 Nodes = select, {{ $proxyNames }}, hidden=1\n\n[Rule]\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Apple/Apple_All.list, 🍎 Apple\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Google/Google.list, 🔍 Google\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/GitHub/GitHub.list, 🪟 Microsoft\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Microsoft/Microsoft.list, 🪟 Microsoft\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/HBO/HBO.list, 📺 GlobalMedia\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Disney/Disney.list, 📺 GlobalMedia\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/TikTok/TikTok.list, 📺 GlobalMedia\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Netflix/Netflix.list, 📺 GlobalMedia\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/GlobalMedia/GlobalMedia_All_No_Resolve.list, 📺 GlobalMedia\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Telegram/Telegram.list, 📟 Telegram\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/OpenAI/OpenAI.list, 🤖 AI\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Gemini/Gemini.list, 🤖 AI\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Copilot/Copilot.list, 🤖 AI\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Claude/Claude.list, 🤖 AI\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Crypto/Crypto.list, 🪙 Crypto\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Cryptocurrency/Cryptocurrency.list, 🪙 Crypto\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Game/Game.list, 🎮 Game\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Global/Global_All_No_Resolve.list, 🚀 Proxy\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/ChinaMax/ChinaMax_All_No_Resolve.list, 🇨🇳 China\nRULE-SET, https://cdn.jsdmirror.com/gh/perfect-panel/rules/rule/Surge/Lan/Lan.list, 🎯 Direct\n\nGEOIP, CN, 🇨🇳 China\nFINAL, 🐠 Final, dns-failed\n\n[URL Rewrite]\n^https?:\\/\\/(www.)?g\\.cn https://www.google.com 302\n^https?:\\/\\/(www.)?google\\.cn https://www.google.com 302\n', 'conf', '{}', '2025-08-13 00:12:37.809', '2025-08-15 22:00:50.528'); COMMIT; --- migrate:down -DROP TABLE IF EXISTS `subscribe_application`; diff --git a/migrations/mysql/02102_subscribe_config.sql b/migrations/mysql/02102_subscribe_config.sql index 1c55a260..edb6bfce 100644 --- a/migrations/mysql/02102_subscribe_config.sql +++ b/migrations/mysql/02102_subscribe_config.sql @@ -1,7 +1,4 @@ --- migrate:up INSERT IGNORE INTO `system` (`id`, `category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) VALUES (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'); --- migrate:down - diff --git a/migrations/mysql/02103_delete_application.sql b/migrations/mysql/02103_delete_application.sql index 3409b1ef..648ad651 100644 --- a/migrations/mysql/02103_delete_application.sql +++ b/migrations/mysql/02103_delete_application.sql @@ -1,6 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS `application`; DROP TABLE IF EXISTS `application_version`; DROP TABLE IF EXISTS `application_config`; --- migrate:down - diff --git a/migrations/mysql/02104_system_log.sql b/migrations/mysql/02104_system_log.sql index b66414ff..75b6de39 100644 --- a/migrations/mysql/02104_system_log.sql +++ b/migrations/mysql/02104_system_log.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS `user_balance_log`; DROP TABLE IF EXISTS `user_commission_log`; DROP TABLE IF EXISTS `user_gift_amount_log`; @@ -18,110 +17,3 @@ CREATE TABLE `system_logs` ( KEY `idx_type` (`type`), KEY `idx_object_id` (`object_id`) ) 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`; diff --git a/migrations/mysql/02105_node.sql b/migrations/mysql/02105_node.sql index b019ce28..44073729 100644 --- a/migrations/mysql/02105_node.sql +++ b/migrations/mysql/02105_node.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS `servers` ( `id` bigint NOT NULL AUTO_INCREMENT, `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`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- migrate:down -DROP TABLE IF EXISTS `nodes`; -DROP TABLE IF EXISTS `servers`; - diff --git a/migrations/mysql/02106_subscribe.sql b/migrations/mysql/02106_subscribe.sql index 67d10dda..f6bad22d 100644 --- a/migrations/mysql/02106_subscribe.sql +++ b/migrations/mysql/02106_subscribe.sql @@ -1,4 +1,3 @@ --- migrate:up ALTER TABLE `subscribe` ADD COLUMN `nodes` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Node IDs', 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`; --- 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'; - diff --git a/migrations/mysql/02107_log_setting.sql b/migrations/mysql/02107_log_setting.sql index a3b75910..f5981c0b 100644 --- a/migrations/mysql/02107_log_setting.sql +++ b/migrations/mysql/02107_log_setting.sql @@ -1,7 +1,4 @@ --- migrate:up INSERT IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) VALUES ('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'); --- migrate:down - diff --git a/migrations/mysql/02108_user_referral.sql b/migrations/mysql/02108_user_referral.sql index 6a1f55ec..4bd4a020 100644 --- a/migrations/mysql/02108_user_referral.sql +++ b/migrations/mysql/02108_user_referral.sql @@ -1,4 +1,3 @@ --- migrate:up ALTER TABLE `user` ADD COLUMN `referral_percentage` TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Referral Percentage' @@ -7,7 +6,3 @@ ALTER TABLE `user` COMMENT 'Only First Purchase' AFTER `referral_percentage`; --- migrate:down -ALTER TABLE `user` -DROP COLUMN `referral_percentage`, -DROP COLUMN `only_first_purchase`; diff --git a/migrations/mysql/02109_node_sort.sql b/migrations/mysql/02109_node_sort.sql index b048e1a0..49ea18b0 100644 --- a/migrations/mysql/02109_node_sort.sql +++ b/migrations/mysql/02109_node_sort.sql @@ -1,7 +1,3 @@ --- migrate:up ALTER TABLE `nodes` ADD COLUMN `sort` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Sort' AFTER `enabled`; --- migrate:down -ALTER TABLE `nodes` -DROP COLUMN `sort`; diff --git a/migrations/mysql/02110_traffic_log_index.sql b/migrations/mysql/02110_traffic_log_index.sql index 8cb62b3c..411378c5 100644 --- a/migrations/mysql/02110_traffic_log_index.sql +++ b/migrations/mysql/02110_traffic_log_index.sql @@ -1,6 +1,2 @@ --- migrate:up 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; - diff --git a/migrations/mysql/02111_clear_table.sql b/migrations/mysql/02111_clear_table.sql index e50b5994..94c2cb18 100644 --- a/migrations/mysql/02111_clear_table.sql +++ b/migrations/mysql/02111_clear_table.sql @@ -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 `sms`; diff --git a/migrations/mysql/02112_subscribe.sql b/migrations/mysql/02112_subscribe.sql index 296341c4..83127f5a 100644 --- a/migrations/mysql/02112_subscribe.sql +++ b/migrations/mysql/02112_subscribe.sql @@ -1,4 +1,3 @@ --- migrate:up ALTER TABLE `subscribe` DROP COLUMN `group_id`, ADD COLUMN `language` VARCHAR(255) NOT NULL DEFAULT '' @@ -6,5 +5,3 @@ ADD COLUMN `language` VARCHAR(255) NOT NULL DEFAULT '' AFTER `name`; DROP TABLE IF EXISTS `subscribe_group`; --- migrate:down - diff --git a/migrations/mysql/02113_task.sql b/migrations/mysql/02113_task.sql index e9b432fd..40eeff3d 100644 --- a/migrations/mysql/02113_task.sql +++ b/migrations/mysql/02113_task.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS `email_task`; CREATE TABLE `task` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', @@ -13,5 +12,3 @@ CREATE TABLE `task` ( `updated_at` datetime(3) DEFAULT NULL COMMENT 'Update Time', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; --- migrate:down - diff --git a/migrations/mysql/02114_node_config.sql b/migrations/mysql/02114_node_config.sql index 8a5710fd..9b8a50fd 100644 --- a/migrations/mysql/02114_node_config.sql +++ b/migrations/mysql/02114_node_config.sql @@ -1,4 +1,3 @@ --- migrate:up INSERT IGNORE INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`) 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', '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'); --- migrate:down - diff --git a/migrations/mysql/02115_ads.sql b/migrations/mysql/02115_ads.sql index d044ce7e..b9d864d7 100644 --- a/migrations/mysql/02115_ads.sql +++ b/migrations/mysql/02115_ads.sql @@ -1,4 +1,3 @@ --- migrate:up -- 只有当 ads 表中不存在 description 字段时才添加 SET @col_exists := ( @@ -20,5 +19,3 @@ PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt; --- migrate:down - diff --git a/migrations/mysql/02116_user_algo.sql b/migrations/mysql/02116_user_algo.sql index ca1bbeb2..4fc42a22 100644 --- a/migrations/mysql/02116_user_algo.sql +++ b/migrations/mysql/02116_user_algo.sql @@ -1,4 +1,3 @@ --- migrate:up -- 添加 algo 列(如果不存在) SET @dbname = DATABASE(); SET @tablename = 'user'; @@ -35,8 +34,3 @@ PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; --- migrate:down -ALTER TABLE `user` -DROP COLUMN `algo`, - DROP COLUMN `salt`; - diff --git a/migrations/mysql/02117_site_custom_data.sql b/migrations/mysql/02117_site_custom_data.sql index 35aae07e..f742bdcc 100644 --- a/migrations/mysql/02117_site_custom_data.sql +++ b/migrations/mysql/02117_site_custom_data.sql @@ -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`) SELECT 'site', 'CustomData', '{ "kr_website_id": "" diff --git a/migrations/mysql/02118_traffic_log_idx.sql b/migrations/mysql/02118_traffic_log_idx.sql index 1d6a5f01..11df14f3 100644 --- a/migrations/mysql/02118_traffic_log_idx.sql +++ b/migrations/mysql/02118_traffic_log_idx.sql @@ -1,6 +1,2 @@ --- migrate:up ALTER TABLE traffic_log ADD INDEX idx_timestamp (timestamp); --- migrate:down -ALTER TABLE traffic_log DROP INDEX idx_timestamp; - diff --git a/migrations/mysql/02119_user_subscribe_note.sql b/migrations/mysql/02119_user_subscribe_note.sql index 4a82bcbf..821806b8 100644 --- a/migrations/mysql/02119_user_subscribe_note.sql +++ b/migrations/mysql/02119_user_subscribe_note.sql @@ -1,10 +1,5 @@ --- migrate:up ALTER TABLE `user_subscribe` ADD COLUMN `note` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'User note for subscription' AFTER `status`; --- migrate:down -ALTER TABLE `user_subscribe` -DROP COLUMN `note`; - diff --git a/migrations/mysql/02120_user_rules.sql b/migrations/mysql/02120_user_rules.sql index a0bc08f7..454c24f4 100644 --- a/migrations/mysql/02120_user_rules.sql +++ b/migrations/mysql/02120_user_rules.sql @@ -1,10 +1,5 @@ --- migrate:up ALTER TABLE `user` ADD COLUMN `rules` TEXT NULL COMMENT 'User rules for subscription' AFTER `created_at`; --- migrate:down -ALTER TABLE `user` -DROP COLUMN IF EXISTS `rules`; - diff --git a/migrations/mysql/02121_user_withdrawal.sql b/migrations/mysql/02121_user_withdrawal.sql index a9aefd9c..212836d9 100644 --- a/migrations/mysql/02121_user_withdrawal.sql +++ b/migrations/mysql/02121_user_withdrawal.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS `withdrawals` ( `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `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`) VALUES ('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'; - diff --git a/migrations/mysql/02122_server.sql b/migrations/mysql/02122_server.sql index 2180ffd9..b0b3d1f8 100644 --- a/migrations/mysql/02122_server.sql +++ b/migrations/mysql/02122_server.sql @@ -1,31 +1 @@ --- migrate:up 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; - diff --git a/migrations/mysql/02123_subscribe_original.sql b/migrations/mysql/02123_subscribe_original.sql index 6ac68f32..4a0229e1 100644 --- a/migrations/mysql/02123_subscribe_original.sql +++ b/migrations/mysql/02123_subscribe_original.sql @@ -1,8 +1,3 @@ --- migrate:up 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`; --- migrate:down -ALTER TABLE `subscribe` -DROP COLUMN `show_original_price`; - diff --git a/migrations/mysql/02124_server_group_delete.sql b/migrations/mysql/02124_server_group_delete.sql index e716833e..e26f5fc7 100644 --- a/migrations/mysql/02124_server_group_delete.sql +++ b/migrations/mysql/02124_server_group_delete.sql @@ -1,4 +1 @@ --- migrate:up DROP TABLE IF EXISTS `server_group`; --- migrate:down - diff --git a/migrations/mysql/02125_subscribe_stock.sql b/migrations/mysql/02125_subscribe_stock.sql index 73d08d2b..c347495d 100644 --- a/migrations/mysql/02125_subscribe_stock.sql +++ b/migrations/mysql/02125_subscribe_stock.sql @@ -1,11 +1,4 @@ --- migrate:up -- Update the `subscribe` table to set `inventory` to -1 where it is currently 0 UPDATE `subscribe` SET `inventory` = -1 WHERE `inventory` = 0; --- migrate:down - --- This migration script reverts the inventory values in the 'subscribe' table -UPDATE `subscribe` -SET `inventory` = 0 -WHERE `inventory` = -1; diff --git a/migrations/mysql/02126_system_log_idx.sql b/migrations/mysql/02126_system_log_idx.sql index bf29cee3..eff09df8 100644 --- a/migrations/mysql/02126_system_log_idx.sql +++ b/migrations/mysql/02126_system_log_idx.sql @@ -1,6 +1,2 @@ --- migrate:up CREATE INDEX idx_type_date ON system_logs (type, date); --- migrate:down -DROP INDEX idx_type_date ON system_logs; - diff --git a/migrations/mysql/02127_search_indexes.sql b/migrations/mysql/02127_search_indexes.sql index 85b51713..b1894c2b 100644 --- a/migrations/mysql/02127_search_indexes.sql +++ b/migrations/mysql/02127_search_indexes.sql @@ -1,4 +1,3 @@ --- migrate:up SET @index_exists = (SELECT COUNT(1) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = DATABASE() @@ -131,136 +130,3 @@ PREPARE stmt FROM @sql; EXECUTE 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; - diff --git a/migrations/mysql/02128_server_config_override.sql b/migrations/mysql/02128_server_config_override.sql index 20256c5d..0227f1d1 100644 --- a/migrations/mysql/02128_server_config_override.sql +++ b/migrations/mysql/02128_server_config_override.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS `server_config_overrides` ( `id` bigint NOT NULL AUTO_INCREMENT, @@ -15,6 +14,3 @@ CREATE TABLE IF NOT EXISTS `server_config_overrides` DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; --- migrate:down -DROP TABLE IF EXISTS `server_config_overrides`; - diff --git a/migrations/mysql/02129_payment_sort.sql b/migrations/mysql/02129_payment_sort.sql index d3f9eb75..def5a4d7 100644 --- a/migrations/mysql/02129_payment_sort.sql +++ b/migrations/mysql/02129_payment_sort.sql @@ -1,4 +1,3 @@ --- migrate:up SET @column_exists = ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -21,22 +20,3 @@ UPDATE `payment` SET `sort` = `id` 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; - diff --git a/migrations/mysql/02130_subscribe_tutorial.sql b/migrations/mysql/02130_subscribe_tutorial.sql index 5d68a533..81ecf75b 100644 --- a/migrations/mysql/02130_subscribe_tutorial.sql +++ b/migrations/mysql/02130_subscribe_tutorial.sql @@ -1,10 +1,6 @@ --- migrate:up 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' WHERE NOT EXISTS ( SELECT 1 FROM `system` WHERE `category` = 'subscribe' AND `key` = 'ShowTutorial' ); --- migrate:down -DELETE FROM `system` WHERE `category` = 'subscribe' AND `key` = 'ShowTutorial'; - diff --git a/migrations/mysql/02131_timestamptz_last_reported_at.sql b/migrations/mysql/02131_timestamptz_last_reported_at.sql index 0a38ffd3..b929aab5 100644 --- a/migrations/mysql/02131_timestamptz_last_reported_at.sql +++ b/migrations/mysql/02131_timestamptz_last_reported_at.sql @@ -1,9 +1,5 @@ --- migrate:up -- MySQL datetime type does not have timezone support. -- The Go code fix (serverPushStatusLogic.go, serverPushUserTrafficLogic.go) -- removing .UTC() is sufficient for MySQL environments. SELECT 1; --- migrate:down -SELECT 1; - diff --git a/migrations/postgres/00001_init_schema.sql b/migrations/postgres/00001_init_schema.sql index ebc0a45e..5523cde7 100644 --- a/migrations/postgres/00001_init_schema.sql +++ b/migrations/postgres/00001_init_schema.sql @@ -1,5 +1,3 @@ --- migrate:up --- 000001_init_schema.up.sql CREATE TABLE IF NOT EXISTS "ads" ( "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" ( "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - "password" varchar(100) NOT NULL, + "password" varchar(255) NOT NULL, "avatar" text, "balance" bigint DEFAULT '0', "telegram" bigint DEFAULT NULL, @@ -458,37 +456,3 @@ CREATE TABLE IF NOT EXISTS "server_rule_group" 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"; - diff --git a/migrations/postgres/00002_init_basic_data.sql b/migrations/postgres/00002_init_basic_data.sql index 8c053080..fae085a9 100644 --- a/migrations/postgres/00002_init_basic_data.sql +++ b/migrations/postgres/00002_init_basic_data.sql @@ -1,5 +1,3 @@ --- migrate:up --- 000002_init_data.up.sql -- auth_method INSERT INTO "auth_method" ("id", "method", "config", "enabled", "created_at", "updated_at") 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('"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); - diff --git a/migrations/postgres/02003_update_payment.sql b/migrations/postgres/02003_update_payment.sql index 76acfd6e..c757703f 100644 --- a/migrations/postgres/02003_update_payment.sql +++ b/migrations/postgres/02003_update_payment.sql @@ -1,4 +1,3 @@ --- migrate:up -- PostgreSQL version of payment/order compatibility migration. 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 ''; @@ -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 "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; - diff --git a/migrations/postgres/02004_rebuild_rule.sql b/migrations/postgres/02004_rebuild_rule.sql index 2d7d641a..0812765d 100644 --- a/migrations/postgres/02004_rebuild_rule.sql +++ b/migrations/postgres/02004_rebuild_rule.sql @@ -1,4 +1,3 @@ --- migrate:up -- migrations/02003_rebuild_rule.up.sql -- Purpose: rebuilding server rule table -- 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"); --- 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; - diff --git a/migrations/postgres/02005_device_online_record.sql b/migrations/postgres/02005_device_online_record.sql index a7e7d304..3668fa3d 100644 --- a/migrations/postgres/02005_device_online_record.sql +++ b/migrations/postgres/02005_device_online_record.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS "user_device_online_record" ( "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 "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"; - diff --git a/migrations/postgres/02006_reset_subscribe_record.sql b/migrations/postgres/02006_reset_subscribe_record.sql index 94019934..c68a41a5 100644 --- a/migrations/postgres/02006_reset_subscribe_record.sql +++ b/migrations/postgres/02006_reset_subscribe_record.sql @@ -1,4 +1,3 @@ --- migrate:up -- migrations/02008_create_user_reset_subscribe_log.up.sql -- Purpose: Create user_reset_subscribe_log table -- 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_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"; - diff --git a/migrations/postgres/02007_adapte_rule.sql b/migrations/postgres/02007_adapte_rule.sql index 514ba2aa..7517ae8e 100644 --- a/migrations/postgres/02007_adapte_rule.sql +++ b/migrations/postgres/02007_adapte_rule.sql @@ -1,10 +1,4 @@ --- migrate:up ALTER TABLE "server_rule_group" ADD COLUMN "default" BOOLEAN NOT NULL DEFAULT false, ADD COLUMN "type" VARCHAR(100) NOT NULL DEFAULT ''; --- migrate:down -ALTER TABLE "server_rule_group" -DROP COLUMN "default", -DROP COLUMN "type"; - diff --git a/migrations/postgres/02100_task.sql b/migrations/postgres/02100_task.sql index 16f7a738..73f0c191 100644 --- a/migrations/postgres/02100_task.sql +++ b/migrations/postgres/02100_task.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS "email_task"; CREATE TABLE "email_task" ( "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, @@ -21,6 +20,3 @@ CREATE TABLE "email_task" ( PRIMARY KEY ("id") ); --- migrate:down -DROP TABLE IF EXISTS "email_task"; - diff --git a/migrations/postgres/02101_subscribe_application.sql b/migrations/postgres/02101_subscribe_application.sql index 4bcb281c..40272b1d 100644 --- a/migrations/postgres/02101_subscribe_application.sql +++ b/migrations/postgres/02101_subscribe_application.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS "subscribe_application"; CREATE TABLE IF NOT EXISTS "subscribe_application" ( "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, @@ -32,6 +31,3 @@ INSERT INTO "subscribe_application" ("id", "name", "icon", "description", "schem COMMIT; 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"; - diff --git a/migrations/postgres/02102_subscribe_config.sql b/migrations/postgres/02102_subscribe_config.sql index b1028a72..9d61f530 100644 --- a/migrations/postgres/02102_subscribe_config.sql +++ b/migrations/postgres/02102_subscribe_config.sql @@ -1,9 +1,6 @@ --- migrate:up INSERT INTO "system" ("id", "category", "key", "value", "type", "desc", "created_at", "updated_at") VALUES (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; SELECT setval(pg_get_serial_sequence('"system"', 'id'), COALESCE((SELECT MAX("id") FROM "system"), 1), true); --- migrate:down - diff --git a/migrations/postgres/02103_delete_application.sql b/migrations/postgres/02103_delete_application.sql index 16c67f9e..8d01aaeb 100644 --- a/migrations/postgres/02103_delete_application.sql +++ b/migrations/postgres/02103_delete_application.sql @@ -1,7 +1,4 @@ --- migrate:up DROP TABLE IF EXISTS "application"; DROP TABLE IF EXISTS "application_version"; DROP TABLE IF EXISTS "application_config"; --- migrate:down - diff --git a/migrations/postgres/02104_system_log.sql b/migrations/postgres/02104_system_log.sql index bf351d7a..774c47af 100644 --- a/migrations/postgres/02104_system_log.sql +++ b/migrations/postgres/02104_system_log.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS "user_balance_log"; DROP TABLE IF EXISTS "user_commission_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_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"; - diff --git a/migrations/postgres/02105_node.sql b/migrations/postgres/02105_node.sql index d5e28496..faf33301 100644 --- a/migrations/postgres/02105_node.sql +++ b/migrations/postgres/02105_node.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS "servers" ( "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "name" varchar(100) NOT NULL DEFAULT '', @@ -27,7 +26,3 @@ CREATE TABLE IF NOT EXISTS "nodes" ( PRIMARY KEY ("id") ); --- migrate:down -DROP TABLE IF EXISTS "nodes"; -DROP TABLE IF EXISTS "servers"; - diff --git a/migrations/postgres/02106_subscribe.sql b/migrations/postgres/02106_subscribe.sql index 529ec5df..36e5847e 100644 --- a/migrations/postgres/02106_subscribe.sql +++ b/migrations/postgres/02106_subscribe.sql @@ -1,4 +1,3 @@ --- migrate:up ALTER TABLE "subscribe" ADD COLUMN "nodes" 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 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 ''; - diff --git a/migrations/postgres/02107_log_setting.sql b/migrations/postgres/02107_log_setting.sql index 2a722ba2..e332535d 100644 --- a/migrations/postgres/02107_log_setting.sql +++ b/migrations/postgres/02107_log_setting.sql @@ -1,8 +1,5 @@ --- migrate:up INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", "updated_at") VALUES ('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; --- migrate:down - diff --git a/migrations/postgres/02108_user_referral.sql b/migrations/postgres/02108_user_referral.sql index 3a5f8f15..28211db7 100644 --- a/migrations/postgres/02108_user_referral.sql +++ b/migrations/postgres/02108_user_referral.sql @@ -1,10 +1,4 @@ --- migrate:up ALTER TABLE "user" ADD COLUMN "referral_percentage" SMALLINT NOT NULL DEFAULT 0, ADD COLUMN "only_first_purchase" BOOLEAN NOT NULL DEFAULT true; --- migrate:down -ALTER TABLE "user" -DROP COLUMN "referral_percentage", -DROP COLUMN "only_first_purchase"; - diff --git a/migrations/postgres/02109_node_sort.sql b/migrations/postgres/02109_node_sort.sql index 015251c3..aa4a1ee5 100644 --- a/migrations/postgres/02109_node_sort.sql +++ b/migrations/postgres/02109_node_sort.sql @@ -1,8 +1,3 @@ --- migrate:up ALTER TABLE "nodes" ADD COLUMN "sort" INTEGER NOT NULL DEFAULT 0; --- migrate:down -ALTER TABLE "nodes" -DROP COLUMN "sort"; - diff --git a/migrations/postgres/02110_traffic_log_index.sql b/migrations/postgres/02110_traffic_log_index.sql index 3305e194..411378c5 100644 --- a/migrations/postgres/02110_traffic_log_index.sql +++ b/migrations/postgres/02110_traffic_log_index.sql @@ -1,6 +1,2 @@ --- migrate:up 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"; - diff --git a/migrations/postgres/02111_clear_table.sql b/migrations/postgres/02111_clear_table.sql index 51344ce6..60c10e1e 100644 --- a/migrations/postgres/02111_clear_table.sql +++ b/migrations/postgres/02111_clear_table.sql @@ -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 "sms"; diff --git a/migrations/postgres/02112_subscribe.sql b/migrations/postgres/02112_subscribe.sql index cc565f58..22caadd2 100644 --- a/migrations/postgres/02112_subscribe.sql +++ b/migrations/postgres/02112_subscribe.sql @@ -1,8 +1,5 @@ --- migrate:up ALTER TABLE "subscribe" DROP COLUMN "group_id", ADD COLUMN "language" VARCHAR(255) NOT NULL DEFAULT ''; DROP TABLE IF EXISTS "subscribe_group"; --- migrate:down - diff --git a/migrations/postgres/02113_task.sql b/migrations/postgres/02113_task.sql index 2384e47b..a87af3bb 100644 --- a/migrations/postgres/02113_task.sql +++ b/migrations/postgres/02113_task.sql @@ -1,4 +1,3 @@ --- migrate:up DROP TABLE IF EXISTS "email_task"; CREATE TABLE "task" ( "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, @@ -14,5 +13,3 @@ CREATE TABLE "task" ( PRIMARY KEY ("id") ); --- migrate:down - diff --git a/migrations/postgres/02114_node_config.sql b/migrations/postgres/02114_node_config.sql index 16113522..b91c98cf 100644 --- a/migrations/postgres/02114_node_config.sql +++ b/migrations/postgres/02114_node_config.sql @@ -1,4 +1,3 @@ --- migrate:up 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'), ('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', 'Outbound', '', 'string', 'Proxy Outbound', '2025-04-22 14:25:16.637','2025-04-22 14:25:16.637') ON CONFLICT DO NOTHING; --- migrate:down - diff --git a/migrations/postgres/02115_ads.sql b/migrations/postgres/02115_ads.sql index a1087f88..6a45cde6 100644 --- a/migrations/postgres/02115_ads.sql +++ b/migrations/postgres/02115_ads.sql @@ -1,5 +1,2 @@ --- migrate:up ALTER TABLE "ads" ADD COLUMN IF NOT EXISTS "description" VARCHAR(255) DEFAULT ''; --- migrate:down - diff --git a/migrations/postgres/02116_user_algo.sql b/migrations/postgres/02116_user_algo.sql index 63e179c5..35ebc491 100644 --- a/migrations/postgres/02116_user_algo.sql +++ b/migrations/postgres/02116_user_algo.sql @@ -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 "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"; - diff --git a/migrations/postgres/02117_site_custom_data.sql b/migrations/postgres/02117_site_custom_data.sql index f3fcca53..782c7198 100644 --- a/migrations/postgres/02117_site_custom_data.sql +++ b/migrations/postgres/02117_site_custom_data.sql @@ -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") SELECT 'site', 'CustomData', '{ "kr_website_id": "" diff --git a/migrations/postgres/02118_traffic_log_idx.sql b/migrations/postgres/02118_traffic_log_idx.sql index 908a5843..3bc66c52 100644 --- a/migrations/postgres/02118_traffic_log_idx.sql +++ b/migrations/postgres/02118_traffic_log_idx.sql @@ -1,6 +1,2 @@ --- migrate:up CREATE INDEX IF NOT EXISTS "idx_timestamp" ON "traffic_log" ("timestamp"); --- migrate:down -DROP INDEX IF EXISTS "idx_timestamp"; - diff --git a/migrations/postgres/02119_user_subscribe_note.sql b/migrations/postgres/02119_user_subscribe_note.sql index 059f1369..0da811fd 100644 --- a/migrations/postgres/02119_user_subscribe_note.sql +++ b/migrations/postgres/02119_user_subscribe_note.sql @@ -1,8 +1,3 @@ --- migrate:up ALTER TABLE "user_subscribe" ADD COLUMN "note" VARCHAR(500) NOT NULL DEFAULT ''; --- migrate:down -ALTER TABLE "user_subscribe" -DROP COLUMN "note"; - diff --git a/migrations/postgres/02120_user_rules.sql b/migrations/postgres/02120_user_rules.sql index 9f3e7312..b61e04dc 100644 --- a/migrations/postgres/02120_user_rules.sql +++ b/migrations/postgres/02120_user_rules.sql @@ -1,8 +1,3 @@ --- migrate:up ALTER TABLE "user" ADD COLUMN "rules" TEXT NULL; --- migrate:down -ALTER TABLE "user" -DROP COLUMN IF EXISTS "rules"; - diff --git a/migrations/postgres/02121_user_withdrawal.sql b/migrations/postgres/02121_user_withdrawal.sql index 1a9e73fe..1184c4c5 100644 --- a/migrations/postgres/02121_user_withdrawal.sql +++ b/migrations/postgres/02121_user_withdrawal.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS "withdrawals" ( "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "user_id" BIGINT NOT NULL, @@ -15,9 +14,3 @@ INSERT INTO "system" ("category", "key", "value", "type", "desc", "created_at", VALUES ('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'; - diff --git a/migrations/postgres/02122_server.sql b/migrations/postgres/02122_server.sql index 6a1769ec..984fcb12 100644 --- a/migrations/postgres/02122_server.sql +++ b/migrations/postgres/02122_server.sql @@ -1,30 +1,2 @@ --- migrate:up 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"); - diff --git a/migrations/postgres/02123_subscribe_original.sql b/migrations/postgres/02123_subscribe_original.sql index 75572dd0..9a9728c2 100644 --- a/migrations/postgres/02123_subscribe_original.sql +++ b/migrations/postgres/02123_subscribe_original.sql @@ -1,8 +1,3 @@ --- migrate:up ALTER TABLE "subscribe" ADD COLUMN "show_original_price" BOOLEAN NOT NULL DEFAULT false; --- migrate:down -ALTER TABLE "subscribe" -DROP COLUMN "show_original_price"; - diff --git a/migrations/postgres/02124_server_group_delete.sql b/migrations/postgres/02124_server_group_delete.sql index 89e40a4a..eaeafb60 100644 --- a/migrations/postgres/02124_server_group_delete.sql +++ b/migrations/postgres/02124_server_group_delete.sql @@ -1,5 +1,2 @@ --- migrate:up DROP TABLE IF EXISTS "server_group"; --- migrate:down - diff --git a/migrations/postgres/02125_subscribe_stock.sql b/migrations/postgres/02125_subscribe_stock.sql index eeaafde5..cb6b9e59 100644 --- a/migrations/postgres/02125_subscribe_stock.sql +++ b/migrations/postgres/02125_subscribe_stock.sql @@ -1,12 +1,5 @@ --- migrate:up -- Update the "subscribe" table to set "inventory" to -1 where it is currently 0 UPDATE "subscribe" SET "inventory" = -1 WHERE "inventory" = 0; --- migrate:down --- This migration script reverts the inventory values in the 'subscribe' table -UPDATE "subscribe" -SET "inventory" = 0 -WHERE "inventory" = -1; - diff --git a/migrations/postgres/02126_system_log_idx.sql b/migrations/postgres/02126_system_log_idx.sql index bf02437e..eff09df8 100644 --- a/migrations/postgres/02126_system_log_idx.sql +++ b/migrations/postgres/02126_system_log_idx.sql @@ -1,6 +1,2 @@ --- migrate:up CREATE INDEX idx_type_date ON system_logs (type, date); --- migrate:down -DROP INDEX IF EXISTS "idx_type_date"; - diff --git a/migrations/postgres/02127_search_indexes.sql b/migrations/postgres/02127_search_indexes.sql index 90836888..db226dea 100644 --- a/migrations/postgres/02127_search_indexes.sql +++ b/migrations/postgres/02127_search_indexes.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE EXTENSION IF NOT EXISTS pg_trgm; 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_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"; - diff --git a/migrations/postgres/02128_server_config_override.sql b/migrations/postgres/02128_server_config_override.sql index bb8c23da..41995724 100644 --- a/migrations/postgres/02128_server_config_override.sql +++ b/migrations/postgres/02128_server_config_override.sql @@ -1,4 +1,3 @@ --- migrate:up CREATE TABLE IF NOT EXISTS "server_config_overrides" ( "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") ); --- migrate:down -DROP TABLE IF EXISTS "server_config_overrides"; - diff --git a/migrations/postgres/02129_payment_sort.sql b/migrations/postgres/02129_payment_sort.sql index f315e764..26df4811 100644 --- a/migrations/postgres/02129_payment_sort.sql +++ b/migrations/postgres/02129_payment_sort.sql @@ -1,4 +1,3 @@ --- migrate:up ALTER TABLE "payment" ADD COLUMN IF NOT EXISTS "sort" bigint NOT NULL DEFAULT 0; @@ -6,7 +5,3 @@ UPDATE "payment" SET "sort" = "id" WHERE "sort" = 0; --- migrate:down -ALTER TABLE "payment" - DROP COLUMN IF EXISTS "sort"; - diff --git a/migrations/postgres/02130_subscribe_tutorial.sql b/migrations/postgres/02130_subscribe_tutorial.sql index 1923abcd..d024da46 100644 --- a/migrations/postgres/02130_subscribe_tutorial.sql +++ b/migrations/postgres/02130_subscribe_tutorial.sql @@ -1,10 +1,6 @@ --- migrate:up 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' WHERE NOT EXISTS ( SELECT 1 FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial' ); --- migrate:down -DELETE FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial'; - diff --git a/migrations/postgres/02131_timestamptz_last_reported_at.sql b/migrations/postgres/02131_timestamptz_last_reported_at.sql index 36d81008..9e06fdf1 100644 --- a/migrations/postgres/02131_timestamptz_last_reported_at.sql +++ b/migrations/postgres/02131_timestamptz_last_reported_at.sql @@ -1,10 +1,4 @@ --- migrate:up ALTER TABLE "servers" ALTER COLUMN "last_reported_at" TYPE timestamptz 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'; - diff --git a/src/handler/routes.rs b/src/handler/routes.rs index 8bcd21d6..a8104822 100644 --- a/src/handler/routes.rs +++ b/src/handler/routes.rs @@ -324,7 +324,7 @@ pub fn register_routes(state: AppState) -> Router<()> { .route("/v1/server/push", post(server_push_user_traffic)) .route("/v1/server/status", post(server_push_status)) .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("/", get(pan_domain_subscribe_handler)) .route("/v1/telegram", post(telegram_handler)); diff --git a/src/migration.rs b/src/migration.rs index dd7dc64c..203d61b9 100644 --- a/src/migration.rs +++ b/src/migration.rs @@ -14,7 +14,12 @@ mod mysql_migrations { mod postgres_migrations { #![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; @@ -24,7 +29,7 @@ use crate::repository::Db; /// Run all pending migrations for the detected database dialect. pub async fn run_migrations(db: &Db) -> Result<(), sqlx::migrate::MigrateError> { 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, } } @@ -60,6 +65,7 @@ async fn create_admin_user_pg( } let now = chrono::Utc::now().timestamp_millis(); + let now_ts = chrono::Utc::now(); // chrono::DateTime -> PG timestamp let password_hash = hash_password_pbkdf2(password); let refer_code = generate_invite_code(); @@ -68,12 +74,12 @@ async fn create_admin_user_pg( gift_amount, enable, enable_balance_notify, enable_login_notify, enable_subscribe_notify, 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(&refer_code) - .bind(now) - .bind(now) + .bind(now_ts) + .bind(now_ts) .execute(pool) .await .map_err(|e| { @@ -93,12 +99,12 @@ async fn create_admin_user_pg( sqlx::query( 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(email) - .bind(now) - .bind(now) + .bind(now_ts) + .bind(now_ts) .execute(pool) .await .map_err(|e| { diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 5a15659a..9cf443c1 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -38,7 +38,7 @@ impl Service { Self::register( &scheduler, types::SCHEDULER_CHECK_SUBSCRIPTION, - "@every 60s", + "*/30 * * * * *", "default", ) .await?; @@ -47,7 +47,7 @@ impl Service { Self::register( &scheduler, types::SCHEDULER_RESET_TRAFFIC, - "30 0 * * *", + "0 30 0 * * *", "default", ) .await?; @@ -56,7 +56,7 @@ impl Service { Self::register( &scheduler, types::SCHEDULER_TRAFFIC_STAT, - "0 0 * * *", + "0 0 0 * * *", "default", ) .await?; @@ -65,7 +65,7 @@ impl Service { Self::register( &scheduler, types::FORTHWITH_QUOTA_TASK, - "0 1 * * *", + "0 0 1 * * *", "default", ) .await?; From 0305d058c4259c94fd7ccec6bcd2d02fb4fb58fe Mon Sep 17 00:00:00 2001 From: Ember Moth Date: Sun, 5 Jul 2026 22:37:44 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0ddd651d..d24da4ca 100644 --- a/README.md +++ b/README.md @@ -235,10 +235,10 @@ Trace: ## Star History - + - - - Star History Chart + + + Star History Chart