Files
schoolNews/docker/init-db/01-init-database.sql
2025-11-24 16:53:17 +08:00

30 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ========================================
-- 校园新闻管理系统数据库初始化脚本
--
-- 注意:
-- 1. 本脚本仅在数据库首次创建时执行
-- 2. 如果数据库已存在请手动执行或使用02-check-init.sh
-- ========================================
-- 创建数据库(如果不存在)
CREATE DATABASE IF NOT EXISTS school_news
DEFAULT CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
USE school_news;
-- 检查表是否已存在,避免重复初始化
-- 创建一个标记表记录初始化状态
CREATE TABLE IF NOT EXISTS _db_init_status (
id INT PRIMARY KEY AUTO_INCREMENT,
script_name VARCHAR(255) NOT NULL UNIQUE,
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(50) DEFAULT 'init'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 记录初始化标记
INSERT IGNORE INTO _db_init_status (script_name) VALUES ('01-init-database.sql');
-- 提示信息
SELECT CONCAT('数据库 school_news 初始化完成。请将您的表结构脚本放在 02-create-tables.sql 中') AS message;