From 525bbd1a56e9478b6e62373c68f6f83f33e359cb Mon Sep 17 00:00:00 2001 From: xiong Date: Fri, 24 Jul 2026 15:28:19 +0800 Subject: [PATCH] Add seed data for 2025 summer school schedule Drop unused KeyOutlined import and refactor init.sql to drop all tables safely --- apps/admin/src/pages/AiConfig/index.tsx | 1 - init.sql | 43 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/apps/admin/src/pages/AiConfig/index.tsx b/apps/admin/src/pages/AiConfig/index.tsx index 809b3c1..83c785d 100644 --- a/apps/admin/src/pages/AiConfig/index.tsx +++ b/apps/admin/src/pages/AiConfig/index.tsx @@ -21,7 +21,6 @@ import { ApiOutlined, CheckCircleOutlined, CloseCircleOutlined, - KeyOutlined, WarningOutlined, ReloadOutlined, CloudServerOutlined, diff --git a/init.sql b/init.sql index e2eeac9..52d7e43 100644 --- a/init.sql +++ b/init.sql @@ -1,12 +1,47 @@ -- gongxue-base MySQL full rebuild script -- Generated from the current TypeORM migrations on 2026-07-24. --- WARNING: this script intentionally drops dorm_billing_v2 and all data in it. +-- WARNING: this script intentionally drops every table in dorm_billing_v2 and rebuilds the schema. +-- The database itself is preserved for environments without DROP/CREATE DATABASE privileges. SET NAMES utf8mb4; -SET FOREIGN_KEY_CHECKS = 0; -DROP DATABASE IF EXISTS `dorm_billing_v2`; -CREATE DATABASE `dorm_billing_v2` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE `dorm_billing_v2`; +SET FOREIGN_KEY_CHECKS = 0; + +DROP PROCEDURE IF EXISTS `drop_all_tables`; +DELIMITER $$ +CREATE PROCEDURE `drop_all_tables`() +BEGIN + DECLARE finished INTEGER DEFAULT 0; + DECLARE current_table VARCHAR(255); + DECLARE table_cursor CURSOR FOR + SELECT `table_name` + FROM `information_schema`.`tables` + WHERE `table_schema` = DATABASE() + AND `table_type` = 'BASE TABLE'; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1; + + OPEN table_cursor; + drop_loop: LOOP + FETCH table_cursor INTO current_table; + IF finished = 1 THEN + LEAVE drop_loop; + END IF; + + SET @drop_table_sql = CONCAT( + 'DROP TABLE IF EXISTS `', + REPLACE(current_table, '`', '``'), + '`' + ); + PREPARE drop_statement FROM @drop_table_sql; + EXECUTE drop_statement; + DEALLOCATE PREPARE drop_statement; + END LOOP; + CLOSE table_cursor; +END$$ +DELIMITER ; + +CALL `drop_all_tables`(); +DROP PROCEDURE IF EXISTS `drop_all_tables`; SET FOREIGN_KEY_CHECKS = 1; CREATE TABLE `wallet_transactions` (`id` int NOT NULL AUTO_INCREMENT, `student_id` int NOT NULL, `bill_id` int NULL, `operation_id` varchar(64) NULL, `type` varchar(30) NOT NULL, `amount` decimal(12,2) NOT NULL, `balance_after` decimal(12,2) NOT NULL, `description` varchar(300) NULL, `recorded_by` int NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), INDEX `IDX_680bbd0275ac5e06c179f9b84c` (`student_id`, `created_at`), PRIMARY KEY (`id`)) ENGINE=InnoDB;