From 67bfc9bd72e2de9d49e539fcf559034ebd9b4226 Mon Sep 17 00:00:00 2001 From: Ember Moth Date: Sun, 5 Jul 2026 20:36:25 +0800 Subject: [PATCH] add MySQL + PG down.sql --- migrations/mysql/00001_init_schema.down.sql | 36 +++++ .../mysql/00002_init_basic_data.down.sql | 21 +++ .../mysql/02003_update_payment.down.sql | 72 ++++++++++ migrations/mysql/02004_rebuild_rule.down.sql | 4 + .../mysql/02005_device_online_record.down.sql | 52 +++++++ .../02006_reset_subscribe_record.down.sql | 5 + migrations/mysql/02007_adapte_rule.down.sql | 3 + migrations/mysql/02100_task.down.sql | 1 + .../02101_subscribe_application.down.sql | 1 + .../mysql/02102_subscribe_config.down.sql | 0 .../mysql/02103_delete_application.down.sql | 0 migrations/mysql/02104_system_log.down.sql | 106 ++++++++++++++ migrations/mysql/02105_node.down.sql | 2 + migrations/mysql/02106_subscribe.down.sql | 5 + migrations/mysql/02107_log_setting.down.sql | 0 migrations/mysql/02108_user_referral.down.sql | 3 + migrations/mysql/02109_node_sort.down.sql | 2 + .../mysql/02110_traffic_log_index.down.sql | 1 + migrations/mysql/02111_clear_table.down.sql | 2 + migrations/mysql/02112_subscribe.down.sql | 0 migrations/mysql/02113_task.down.sql | 0 migrations/mysql/02114_node_config.down.sql | 0 migrations/mysql/02115_ads.down.sql | 0 migrations/mysql/02116_user_algo.down.sql | 3 + .../mysql/02117_site_custom_data.down.sql | 7 + .../mysql/02118_traffic_log_idx.down.sql | 1 + .../mysql/02119_user_subscribe_note.down.sql | 2 + migrations/mysql/02120_user_rules.down.sql | 2 + .../mysql/02121_user_withdrawal.down.sql | 5 + migrations/mysql/02122_server.down.sql | 27 ++++ .../mysql/02123_subscribe_original.down.sql | 2 + .../mysql/02124_server_group_delete.down.sql | 0 .../mysql/02125_subscribe_stock.down.sql | 5 + .../mysql/02126_system_log_idx.down.sql | 1 + .../mysql/02127_search_indexes.down.sql | 131 ++++++++++++++++++ .../02128_server_config_override.down.sql | 1 + migrations/mysql/02129_payment_sort.down.sql | 17 +++ .../mysql/02130_subscribe_tutorial.down.sql | 1 + ...2131_timestamptz_last_reported_at.down.sql | 1 + .../postgres/00001_init_schema.down.sql | 32 +++++ .../postgres/00002_init_basic_data.down.sql | 15 ++ .../postgres/02003_update_payment.down.sql | 5 + .../postgres/02004_rebuild_rule.down.sql | 4 + .../02005_device_online_record.down.sql | 4 + .../02006_reset_subscribe_record.down.sql | 5 + .../postgres/02007_adapte_rule.down.sql | 3 + migrations/postgres/02100_task.down.sql | 1 + .../02101_subscribe_application.down.sql | 1 + .../postgres/02102_subscribe_config.down.sql | 0 .../02103_delete_application.down.sql | 0 migrations/postgres/02104_system_log.down.sql | 85 ++++++++++++ migrations/postgres/02105_node.down.sql | 2 + migrations/postgres/02106_subscribe.down.sql | 5 + .../postgres/02107_log_setting.down.sql | 0 .../postgres/02108_user_referral.down.sql | 3 + migrations/postgres/02109_node_sort.down.sql | 2 + .../postgres/02110_traffic_log_index.down.sql | 1 + .../postgres/02111_clear_table.down.sql | 2 + migrations/postgres/02112_subscribe.down.sql | 0 migrations/postgres/02113_task.down.sql | 0 .../postgres/02114_node_config.down.sql | 0 migrations/postgres/02115_ads.down.sql | 0 migrations/postgres/02116_user_algo.down.sql | 2 + .../postgres/02117_site_custom_data.down.sql | 7 + .../postgres/02118_traffic_log_idx.down.sql | 1 + .../02119_user_subscribe_note.down.sql | 2 + migrations/postgres/02120_user_rules.down.sql | 2 + .../postgres/02121_user_withdrawal.down.sql | 4 + migrations/postgres/02122_server.down.sql | 25 ++++ .../02123_subscribe_original.down.sql | 2 + .../02124_server_group_delete.down.sql | 0 .../postgres/02125_subscribe_stock.down.sql | 4 + .../postgres/02126_system_log_idx.down.sql | 1 + .../postgres/02127_search_indexes.down.sql | 29 ++++ .../02128_server_config_override.down.sql | 1 + .../postgres/02129_payment_sort.down.sql | 2 + .../02130_subscribe_tutorial.down.sql | 1 + ...2131_timestamptz_last_reported_at.down.sql | 3 + 78 files changed, 778 insertions(+) create mode 100644 migrations/mysql/00001_init_schema.down.sql create mode 100644 migrations/mysql/00002_init_basic_data.down.sql create mode 100644 migrations/mysql/02003_update_payment.down.sql create mode 100644 migrations/mysql/02004_rebuild_rule.down.sql create mode 100644 migrations/mysql/02005_device_online_record.down.sql create mode 100644 migrations/mysql/02006_reset_subscribe_record.down.sql create mode 100644 migrations/mysql/02007_adapte_rule.down.sql create mode 100644 migrations/mysql/02100_task.down.sql create mode 100644 migrations/mysql/02101_subscribe_application.down.sql create mode 100644 migrations/mysql/02102_subscribe_config.down.sql create mode 100644 migrations/mysql/02103_delete_application.down.sql create mode 100644 migrations/mysql/02104_system_log.down.sql create mode 100644 migrations/mysql/02105_node.down.sql create mode 100644 migrations/mysql/02106_subscribe.down.sql create mode 100644 migrations/mysql/02107_log_setting.down.sql create mode 100644 migrations/mysql/02108_user_referral.down.sql create mode 100644 migrations/mysql/02109_node_sort.down.sql create mode 100644 migrations/mysql/02110_traffic_log_index.down.sql create mode 100644 migrations/mysql/02111_clear_table.down.sql create mode 100644 migrations/mysql/02112_subscribe.down.sql create mode 100644 migrations/mysql/02113_task.down.sql create mode 100644 migrations/mysql/02114_node_config.down.sql create mode 100644 migrations/mysql/02115_ads.down.sql create mode 100644 migrations/mysql/02116_user_algo.down.sql create mode 100644 migrations/mysql/02117_site_custom_data.down.sql create mode 100644 migrations/mysql/02118_traffic_log_idx.down.sql create mode 100644 migrations/mysql/02119_user_subscribe_note.down.sql create mode 100644 migrations/mysql/02120_user_rules.down.sql create mode 100644 migrations/mysql/02121_user_withdrawal.down.sql create mode 100644 migrations/mysql/02122_server.down.sql create mode 100644 migrations/mysql/02123_subscribe_original.down.sql create mode 100644 migrations/mysql/02124_server_group_delete.down.sql create mode 100644 migrations/mysql/02125_subscribe_stock.down.sql create mode 100644 migrations/mysql/02126_system_log_idx.down.sql create mode 100644 migrations/mysql/02127_search_indexes.down.sql create mode 100644 migrations/mysql/02128_server_config_override.down.sql create mode 100644 migrations/mysql/02129_payment_sort.down.sql create mode 100644 migrations/mysql/02130_subscribe_tutorial.down.sql create mode 100644 migrations/mysql/02131_timestamptz_last_reported_at.down.sql create mode 100644 migrations/postgres/00001_init_schema.down.sql create mode 100644 migrations/postgres/00002_init_basic_data.down.sql create mode 100644 migrations/postgres/02003_update_payment.down.sql create mode 100644 migrations/postgres/02004_rebuild_rule.down.sql create mode 100644 migrations/postgres/02005_device_online_record.down.sql create mode 100644 migrations/postgres/02006_reset_subscribe_record.down.sql create mode 100644 migrations/postgres/02007_adapte_rule.down.sql create mode 100644 migrations/postgres/02100_task.down.sql create mode 100644 migrations/postgres/02101_subscribe_application.down.sql create mode 100644 migrations/postgres/02102_subscribe_config.down.sql create mode 100644 migrations/postgres/02103_delete_application.down.sql create mode 100644 migrations/postgres/02104_system_log.down.sql create mode 100644 migrations/postgres/02105_node.down.sql create mode 100644 migrations/postgres/02106_subscribe.down.sql create mode 100644 migrations/postgres/02107_log_setting.down.sql create mode 100644 migrations/postgres/02108_user_referral.down.sql create mode 100644 migrations/postgres/02109_node_sort.down.sql create mode 100644 migrations/postgres/02110_traffic_log_index.down.sql create mode 100644 migrations/postgres/02111_clear_table.down.sql create mode 100644 migrations/postgres/02112_subscribe.down.sql create mode 100644 migrations/postgres/02113_task.down.sql create mode 100644 migrations/postgres/02114_node_config.down.sql create mode 100644 migrations/postgres/02115_ads.down.sql create mode 100644 migrations/postgres/02116_user_algo.down.sql create mode 100644 migrations/postgres/02117_site_custom_data.down.sql create mode 100644 migrations/postgres/02118_traffic_log_idx.down.sql create mode 100644 migrations/postgres/02119_user_subscribe_note.down.sql create mode 100644 migrations/postgres/02120_user_rules.down.sql create mode 100644 migrations/postgres/02121_user_withdrawal.down.sql create mode 100644 migrations/postgres/02122_server.down.sql create mode 100644 migrations/postgres/02123_subscribe_original.down.sql create mode 100644 migrations/postgres/02124_server_group_delete.down.sql create mode 100644 migrations/postgres/02125_subscribe_stock.down.sql create mode 100644 migrations/postgres/02126_system_log_idx.down.sql create mode 100644 migrations/postgres/02127_search_indexes.down.sql create mode 100644 migrations/postgres/02128_server_config_override.down.sql create mode 100644 migrations/postgres/02129_payment_sort.down.sql create mode 100644 migrations/postgres/02130_subscribe_tutorial.down.sql create mode 100644 migrations/postgres/02131_timestamptz_last_reported_at.down.sql diff --git a/migrations/mysql/00001_init_schema.down.sql b/migrations/mysql/00001_init_schema.down.sql new file mode 100644 index 00000000..4b8470b7 --- /dev/null +++ b/migrations/mysql/00001_init_schema.down.sql @@ -0,0 +1,36 @@ +-- 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; \ No newline at end of file diff --git a/migrations/mysql/00002_init_basic_data.down.sql b/migrations/mysql/00002_init_basic_data.down.sql new file mode 100644 index 00000000..7d749b28 --- /dev/null +++ b/migrations/mysql/00002_init_basic_data.down.sql @@ -0,0 +1,21 @@ +-- 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; \ No newline at end of file diff --git a/migrations/mysql/02003_update_payment.down.sql b/migrations/mysql/02003_update_payment.down.sql new file mode 100644 index 00000000..51715c21 --- /dev/null +++ b/migrations/mysql/02003_update_payment.down.sql @@ -0,0 +1,72 @@ +-- 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; \ No newline at end of file diff --git a/migrations/mysql/02004_rebuild_rule.down.sql b/migrations/mysql/02004_rebuild_rule.down.sql new file mode 100644 index 00000000..a818ad88 --- /dev/null +++ b/migrations/mysql/02004_rebuild_rule.down.sql @@ -0,0 +1,4 @@ +-- 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; \ No newline at end of file diff --git a/migrations/mysql/02005_device_online_record.down.sql b/migrations/mysql/02005_device_online_record.down.sql new file mode 100644 index 00000000..e571443d --- /dev/null +++ b/migrations/mysql/02005_device_online_record.down.sql @@ -0,0 +1,52 @@ +-- 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; \ No newline at end of file diff --git a/migrations/mysql/02006_reset_subscribe_record.down.sql b/migrations/mysql/02006_reset_subscribe_record.down.sql new file mode 100644 index 00000000..38af3746 --- /dev/null +++ b/migrations/mysql/02006_reset_subscribe_record.down.sql @@ -0,0 +1,5 @@ +-- 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.down.sql b/migrations/mysql/02007_adapte_rule.down.sql new file mode 100644 index 00000000..ed5d22f9 --- /dev/null +++ b/migrations/mysql/02007_adapte_rule.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE `server_rule_group` +DROP COLUMN `default`, +DROP COLUMN `type`; diff --git a/migrations/mysql/02100_task.down.sql b/migrations/mysql/02100_task.down.sql new file mode 100644 index 00000000..0d1f763d --- /dev/null +++ b/migrations/mysql/02100_task.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS `email_task`; \ No newline at end of file diff --git a/migrations/mysql/02101_subscribe_application.down.sql b/migrations/mysql/02101_subscribe_application.down.sql new file mode 100644 index 00000000..bca110af --- /dev/null +++ b/migrations/mysql/02101_subscribe_application.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS `subscribe_application`; \ No newline at end of file diff --git a/migrations/mysql/02102_subscribe_config.down.sql b/migrations/mysql/02102_subscribe_config.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02103_delete_application.down.sql b/migrations/mysql/02103_delete_application.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02104_system_log.down.sql b/migrations/mysql/02104_system_log.down.sql new file mode 100644 index 00000000..2682c97f --- /dev/null +++ b/migrations/mysql/02104_system_log.down.sql @@ -0,0 +1,106 @@ +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`; \ No newline at end of file diff --git a/migrations/mysql/02105_node.down.sql b/migrations/mysql/02105_node.down.sql new file mode 100644 index 00000000..210462e0 --- /dev/null +++ b/migrations/mysql/02105_node.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS `nodes`; +DROP TABLE IF EXISTS `servers`; diff --git a/migrations/mysql/02106_subscribe.down.sql b/migrations/mysql/02106_subscribe.down.sql new file mode 100644 index 00000000..20984b79 --- /dev/null +++ b/migrations/mysql/02106_subscribe.down.sql @@ -0,0 +1,5 @@ +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.down.sql b/migrations/mysql/02107_log_setting.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02108_user_referral.down.sql b/migrations/mysql/02108_user_referral.down.sql new file mode 100644 index 00000000..3bdac5b5 --- /dev/null +++ b/migrations/mysql/02108_user_referral.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE `user` +DROP COLUMN `referral_percentage`, +DROP COLUMN `only_first_purchase`; \ No newline at end of file diff --git a/migrations/mysql/02109_node_sort.down.sql b/migrations/mysql/02109_node_sort.down.sql new file mode 100644 index 00000000..44136469 --- /dev/null +++ b/migrations/mysql/02109_node_sort.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE `nodes` +DROP COLUMN `sort`; \ No newline at end of file diff --git a/migrations/mysql/02110_traffic_log_index.down.sql b/migrations/mysql/02110_traffic_log_index.down.sql new file mode 100644 index 00000000..f42807ca --- /dev/null +++ b/migrations/mysql/02110_traffic_log_index.down.sql @@ -0,0 +1 @@ +DROP INDEX idx_traffic_log_time_user_sub ON traffic_log; diff --git a/migrations/mysql/02111_clear_table.down.sql b/migrations/mysql/02111_clear_table.down.sql new file mode 100644 index 00000000..85c9f3ff --- /dev/null +++ b/migrations/mysql/02111_clear_table.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS `subscribe_type`; +DROP TABLE IF EXISTS `sms`; \ No newline at end of file diff --git a/migrations/mysql/02112_subscribe.down.sql b/migrations/mysql/02112_subscribe.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02113_task.down.sql b/migrations/mysql/02113_task.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02114_node_config.down.sql b/migrations/mysql/02114_node_config.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02115_ads.down.sql b/migrations/mysql/02115_ads.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02116_user_algo.down.sql b/migrations/mysql/02116_user_algo.down.sql new file mode 100644 index 00000000..41644c22 --- /dev/null +++ b/migrations/mysql/02116_user_algo.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE `user` +DROP COLUMN `algo`, + DROP COLUMN `salt`; diff --git a/migrations/mysql/02117_site_custom_data.down.sql b/migrations/mysql/02117_site_custom_data.down.sql new file mode 100644 index 00000000..c8581e8e --- /dev/null +++ b/migrations/mysql/02117_site_custom_data.down.sql @@ -0,0 +1,7 @@ +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' +); diff --git a/migrations/mysql/02118_traffic_log_idx.down.sql b/migrations/mysql/02118_traffic_log_idx.down.sql new file mode 100644 index 00000000..25598dd1 --- /dev/null +++ b/migrations/mysql/02118_traffic_log_idx.down.sql @@ -0,0 +1 @@ +ALTER TABLE traffic_log DROP INDEX idx_timestamp; diff --git a/migrations/mysql/02119_user_subscribe_note.down.sql b/migrations/mysql/02119_user_subscribe_note.down.sql new file mode 100644 index 00000000..60cc0e8a --- /dev/null +++ b/migrations/mysql/02119_user_subscribe_note.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE `user_subscribe` +DROP COLUMN `note`; diff --git a/migrations/mysql/02120_user_rules.down.sql b/migrations/mysql/02120_user_rules.down.sql new file mode 100644 index 00000000..718f4a6a --- /dev/null +++ b/migrations/mysql/02120_user_rules.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE `user` +DROP COLUMN IF EXISTS `rules`; diff --git a/migrations/mysql/02121_user_withdrawal.down.sql b/migrations/mysql/02121_user_withdrawal.down.sql new file mode 100644 index 00000000..4de8bc50 --- /dev/null +++ b/migrations/mysql/02121_user_withdrawal.down.sql @@ -0,0 +1,5 @@ +DROP TABLE IF EXISTS `withdrawals`; + +DELETE FROM `system` +WHERE `category` = 'invite' + AND `key` = 'WithdrawalMethod'; diff --git a/migrations/mysql/02122_server.down.sql b/migrations/mysql/02122_server.down.sql new file mode 100644 index 00000000..7053859b --- /dev/null +++ b/migrations/mysql/02122_server.down.sql @@ -0,0 +1,27 @@ +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.down.sql b/migrations/mysql/02123_subscribe_original.down.sql new file mode 100644 index 00000000..2527d488 --- /dev/null +++ b/migrations/mysql/02123_subscribe_original.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE `subscribe` +DROP COLUMN `show_original_price`; diff --git a/migrations/mysql/02124_server_group_delete.down.sql b/migrations/mysql/02124_server_group_delete.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/mysql/02125_subscribe_stock.down.sql b/migrations/mysql/02125_subscribe_stock.down.sql new file mode 100644 index 00000000..c8482cca --- /dev/null +++ b/migrations/mysql/02125_subscribe_stock.down.sql @@ -0,0 +1,5 @@ + +-- This migration script reverts the inventory values in the 'subscribe' table +UPDATE `subscribe` +SET `inventory` = 0 +WHERE `inventory` = -1; \ No newline at end of file diff --git a/migrations/mysql/02126_system_log_idx.down.sql b/migrations/mysql/02126_system_log_idx.down.sql new file mode 100644 index 00000000..e605bb27 --- /dev/null +++ b/migrations/mysql/02126_system_log_idx.down.sql @@ -0,0 +1 @@ +DROP INDEX idx_type_date ON system_logs; diff --git a/migrations/mysql/02127_search_indexes.down.sql b/migrations/mysql/02127_search_indexes.down.sql new file mode 100644 index 00000000..0623d5ff --- /dev/null +++ b/migrations/mysql/02127_search_indexes.down.sql @@ -0,0 +1,131 @@ +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.down.sql b/migrations/mysql/02128_server_config_override.down.sql new file mode 100644 index 00000000..20a24fe5 --- /dev/null +++ b/migrations/mysql/02128_server_config_override.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS `server_config_overrides`; diff --git a/migrations/mysql/02129_payment_sort.down.sql b/migrations/mysql/02129_payment_sort.down.sql new file mode 100644 index 00000000..e1aa973f --- /dev/null +++ b/migrations/mysql/02129_payment_sort.down.sql @@ -0,0 +1,17 @@ +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.down.sql b/migrations/mysql/02130_subscribe_tutorial.down.sql new file mode 100644 index 00000000..92554ad7 --- /dev/null +++ b/migrations/mysql/02130_subscribe_tutorial.down.sql @@ -0,0 +1 @@ +DELETE FROM `system` WHERE `category` = 'subscribe' AND `key` = 'ShowTutorial'; diff --git a/migrations/mysql/02131_timestamptz_last_reported_at.down.sql b/migrations/mysql/02131_timestamptz_last_reported_at.down.sql new file mode 100644 index 00000000..e0ac49d1 --- /dev/null +++ b/migrations/mysql/02131_timestamptz_last_reported_at.down.sql @@ -0,0 +1 @@ +SELECT 1; diff --git a/migrations/postgres/00001_init_schema.down.sql b/migrations/postgres/00001_init_schema.down.sql new file mode 100644 index 00000000..a7f106f5 --- /dev/null +++ b/migrations/postgres/00001_init_schema.down.sql @@ -0,0 +1,32 @@ +-- 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.down.sql b/migrations/postgres/00002_init_basic_data.down.sql new file mode 100644 index 00000000..ac4e1c91 --- /dev/null +++ b/migrations/postgres/00002_init_basic_data.down.sql @@ -0,0 +1,15 @@ +-- 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.down.sql b/migrations/postgres/02003_update_payment.down.sql new file mode 100644 index 00000000..ef94e390 --- /dev/null +++ b/migrations/postgres/02003_update_payment.down.sql @@ -0,0 +1,5 @@ +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.down.sql b/migrations/postgres/02004_rebuild_rule.down.sql new file mode 100644 index 00000000..d717c27e --- /dev/null +++ b/migrations/postgres/02004_rebuild_rule.down.sql @@ -0,0 +1,4 @@ +-- 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.down.sql b/migrations/postgres/02005_device_online_record.down.sql new file mode 100644 index 00000000..db7e9bf4 --- /dev/null +++ b/migrations/postgres/02005_device_online_record.down.sql @@ -0,0 +1,4 @@ +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.down.sql b/migrations/postgres/02006_reset_subscribe_record.down.sql new file mode 100644 index 00000000..218c652d --- /dev/null +++ b/migrations/postgres/02006_reset_subscribe_record.down.sql @@ -0,0 +1,5 @@ +-- 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.down.sql b/migrations/postgres/02007_adapte_rule.down.sql new file mode 100644 index 00000000..11e98b35 --- /dev/null +++ b/migrations/postgres/02007_adapte_rule.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE "server_rule_group" +DROP COLUMN "default", +DROP COLUMN "type"; diff --git a/migrations/postgres/02100_task.down.sql b/migrations/postgres/02100_task.down.sql new file mode 100644 index 00000000..f20f88a0 --- /dev/null +++ b/migrations/postgres/02100_task.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS "email_task"; diff --git a/migrations/postgres/02101_subscribe_application.down.sql b/migrations/postgres/02101_subscribe_application.down.sql new file mode 100644 index 00000000..5ba84d45 --- /dev/null +++ b/migrations/postgres/02101_subscribe_application.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS "subscribe_application"; diff --git a/migrations/postgres/02102_subscribe_config.down.sql b/migrations/postgres/02102_subscribe_config.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02103_delete_application.down.sql b/migrations/postgres/02103_delete_application.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02104_system_log.down.sql b/migrations/postgres/02104_system_log.down.sql new file mode 100644 index 00000000..89366294 --- /dev/null +++ b/migrations/postgres/02104_system_log.down.sql @@ -0,0 +1,85 @@ +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.down.sql b/migrations/postgres/02105_node.down.sql new file mode 100644 index 00000000..0c0b0385 --- /dev/null +++ b/migrations/postgres/02105_node.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS "nodes"; +DROP TABLE IF EXISTS "servers"; diff --git a/migrations/postgres/02106_subscribe.down.sql b/migrations/postgres/02106_subscribe.down.sql new file mode 100644 index 00000000..bda90302 --- /dev/null +++ b/migrations/postgres/02106_subscribe.down.sql @@ -0,0 +1,5 @@ +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.down.sql b/migrations/postgres/02107_log_setting.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02108_user_referral.down.sql b/migrations/postgres/02108_user_referral.down.sql new file mode 100644 index 00000000..94d2ee55 --- /dev/null +++ b/migrations/postgres/02108_user_referral.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE "user" +DROP COLUMN "referral_percentage", +DROP COLUMN "only_first_purchase"; diff --git a/migrations/postgres/02109_node_sort.down.sql b/migrations/postgres/02109_node_sort.down.sql new file mode 100644 index 00000000..f229cd3d --- /dev/null +++ b/migrations/postgres/02109_node_sort.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE "nodes" +DROP COLUMN "sort"; diff --git a/migrations/postgres/02110_traffic_log_index.down.sql b/migrations/postgres/02110_traffic_log_index.down.sql new file mode 100644 index 00000000..d26f1dfe --- /dev/null +++ b/migrations/postgres/02110_traffic_log_index.down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "idx_traffic_log_time_user_sub"; diff --git a/migrations/postgres/02111_clear_table.down.sql b/migrations/postgres/02111_clear_table.down.sql new file mode 100644 index 00000000..92562a53 --- /dev/null +++ b/migrations/postgres/02111_clear_table.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS "subscribe_type"; +DROP TABLE IF EXISTS "sms"; diff --git a/migrations/postgres/02112_subscribe.down.sql b/migrations/postgres/02112_subscribe.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02113_task.down.sql b/migrations/postgres/02113_task.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02114_node_config.down.sql b/migrations/postgres/02114_node_config.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02115_ads.down.sql b/migrations/postgres/02115_ads.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02116_user_algo.down.sql b/migrations/postgres/02116_user_algo.down.sql new file mode 100644 index 00000000..007c9240 --- /dev/null +++ b/migrations/postgres/02116_user_algo.down.sql @@ -0,0 +1,2 @@ +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.down.sql b/migrations/postgres/02117_site_custom_data.down.sql new file mode 100644 index 00000000..81a70c26 --- /dev/null +++ b/migrations/postgres/02117_site_custom_data.down.sql @@ -0,0 +1,7 @@ +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' +); diff --git a/migrations/postgres/02118_traffic_log_idx.down.sql b/migrations/postgres/02118_traffic_log_idx.down.sql new file mode 100644 index 00000000..ee3aa677 --- /dev/null +++ b/migrations/postgres/02118_traffic_log_idx.down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "idx_timestamp"; diff --git a/migrations/postgres/02119_user_subscribe_note.down.sql b/migrations/postgres/02119_user_subscribe_note.down.sql new file mode 100644 index 00000000..2ac2995a --- /dev/null +++ b/migrations/postgres/02119_user_subscribe_note.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE "user_subscribe" +DROP COLUMN "note"; diff --git a/migrations/postgres/02120_user_rules.down.sql b/migrations/postgres/02120_user_rules.down.sql new file mode 100644 index 00000000..740609bd --- /dev/null +++ b/migrations/postgres/02120_user_rules.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE "user" +DROP COLUMN IF EXISTS "rules"; diff --git a/migrations/postgres/02121_user_withdrawal.down.sql b/migrations/postgres/02121_user_withdrawal.down.sql new file mode 100644 index 00000000..cbce3d5f --- /dev/null +++ b/migrations/postgres/02121_user_withdrawal.down.sql @@ -0,0 +1,4 @@ +DROP TABLE IF EXISTS "withdrawals"; +DELETE FROM "system" +WHERE "category" = 'invite' + AND "key" = 'WithdrawalMethod'; diff --git a/migrations/postgres/02122_server.down.sql b/migrations/postgres/02122_server.down.sql new file mode 100644 index 00000000..007cf024 --- /dev/null +++ b/migrations/postgres/02122_server.down.sql @@ -0,0 +1,25 @@ +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.down.sql b/migrations/postgres/02123_subscribe_original.down.sql new file mode 100644 index 00000000..0eb75750 --- /dev/null +++ b/migrations/postgres/02123_subscribe_original.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE "subscribe" +DROP COLUMN "show_original_price"; diff --git a/migrations/postgres/02124_server_group_delete.down.sql b/migrations/postgres/02124_server_group_delete.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/migrations/postgres/02125_subscribe_stock.down.sql b/migrations/postgres/02125_subscribe_stock.down.sql new file mode 100644 index 00000000..d39924a5 --- /dev/null +++ b/migrations/postgres/02125_subscribe_stock.down.sql @@ -0,0 +1,4 @@ +-- 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.down.sql b/migrations/postgres/02126_system_log_idx.down.sql new file mode 100644 index 00000000..4d8904b5 --- /dev/null +++ b/migrations/postgres/02126_system_log_idx.down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "idx_type_date"; diff --git a/migrations/postgres/02127_search_indexes.down.sql b/migrations/postgres/02127_search_indexes.down.sql new file mode 100644 index 00000000..29d7060b --- /dev/null +++ b/migrations/postgres/02127_search_indexes.down.sql @@ -0,0 +1,29 @@ +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.down.sql b/migrations/postgres/02128_server_config_override.down.sql new file mode 100644 index 00000000..4efa18ca --- /dev/null +++ b/migrations/postgres/02128_server_config_override.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS "server_config_overrides"; diff --git a/migrations/postgres/02129_payment_sort.down.sql b/migrations/postgres/02129_payment_sort.down.sql new file mode 100644 index 00000000..081f73f4 --- /dev/null +++ b/migrations/postgres/02129_payment_sort.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE "payment" + DROP COLUMN IF EXISTS "sort"; diff --git a/migrations/postgres/02130_subscribe_tutorial.down.sql b/migrations/postgres/02130_subscribe_tutorial.down.sql new file mode 100644 index 00000000..4b5aca17 --- /dev/null +++ b/migrations/postgres/02130_subscribe_tutorial.down.sql @@ -0,0 +1 @@ +DELETE FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial'; diff --git a/migrations/postgres/02131_timestamptz_last_reported_at.down.sql b/migrations/postgres/02131_timestamptz_last_reported_at.down.sql new file mode 100644 index 00000000..2dddd6ea --- /dev/null +++ b/migrations/postgres/02131_timestamptz_last_reported_at.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE "servers" + ALTER COLUMN "last_reported_at" TYPE timestamp(3) + USING "last_reported_at" AT TIME ZONE 'UTC';