add MySQL + PG down.sql

This commit is contained in:
Ember Moth
2026-07-05 20:36:25 +08:00
parent 7b3a94308f
commit 67bfc9bd72
78 changed files with 778 additions and 0 deletions
@@ -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";
@@ -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);
@@ -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;
@@ -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;
@@ -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";
@@ -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";
@@ -0,0 +1,3 @@
ALTER TABLE "server_rule_group"
DROP COLUMN "default",
DROP COLUMN "type";
+1
View File
@@ -0,0 +1 @@
DROP TABLE IF EXISTS "email_task";
@@ -0,0 +1 @@
DROP TABLE IF EXISTS "subscribe_application";
@@ -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";
+2
View File
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS "nodes";
DROP TABLE IF EXISTS "servers";
@@ -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 '';
@@ -0,0 +1,3 @@
ALTER TABLE "user"
DROP COLUMN "referral_percentage",
DROP COLUMN "only_first_purchase";
@@ -0,0 +1,2 @@
ALTER TABLE "nodes"
DROP COLUMN "sort";
@@ -0,0 +1 @@
DROP INDEX IF EXISTS "idx_traffic_log_time_user_sub";
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS "subscribe_type";
DROP TABLE IF EXISTS "sms";
@@ -0,0 +1,2 @@
ALTER TABLE "user" DROP COLUMN IF EXISTS "algo";
ALTER TABLE "user" DROP COLUMN IF EXISTS "salt";
@@ -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'
);
@@ -0,0 +1 @@
DROP INDEX IF EXISTS "idx_timestamp";
@@ -0,0 +1,2 @@
ALTER TABLE "user_subscribe"
DROP COLUMN "note";
@@ -0,0 +1,2 @@
ALTER TABLE "user"
DROP COLUMN IF EXISTS "rules";
@@ -0,0 +1,4 @@
DROP TABLE IF EXISTS "withdrawals";
DELETE FROM "system"
WHERE "category" = 'invite'
AND "key" = 'WithdrawalMethod';
+25
View File
@@ -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");
@@ -0,0 +1,2 @@
ALTER TABLE "subscribe"
DROP COLUMN "show_original_price";
@@ -0,0 +1,4 @@
-- This migration script reverts the inventory values in the 'subscribe' table
UPDATE "subscribe"
SET "inventory" = 0
WHERE "inventory" = -1;
@@ -0,0 +1 @@
DROP INDEX IF EXISTS "idx_type_date";
@@ -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";
@@ -0,0 +1 @@
DROP TABLE IF EXISTS "server_config_overrides";
@@ -0,0 +1,2 @@
ALTER TABLE "payment"
DROP COLUMN IF EXISTS "sort";
@@ -0,0 +1 @@
DELETE FROM "system" WHERE "category" = 'subscribe' AND "key" = 'ShowTutorial';
@@ -0,0 +1,3 @@
ALTER TABLE "servers"
ALTER COLUMN "last_reported_at" TYPE timestamp(3)
USING "last_reported_at" AT TIME ZONE 'UTC';