256 lines
5.9 KiB
MySQL
256 lines
5.9 KiB
MySQL
|
|
-- ============================================
|
|||
|
|
-- 阅读平台初始化数据脚本
|
|||
|
|
-- ============================================
|
|||
|
|
-- 用于本地开发和测试
|
|||
|
|
-- 执行方式:mysql -h 8.148.151.56 -u root -p reading_platform < init-data.sql
|
|||
|
|
-- ============================================
|
|||
|
|
|
|||
|
|
USE reading_platform;
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 1. 初始化 admin 用户
|
|||
|
|
-- ============================================
|
|||
|
|
-- 用户名:admin
|
|||
|
|
-- 密码:admin123
|
|||
|
|
-- BCrypt 哈希:$2a$10$DyHiv85Fy.yoslnuxVtw/OmsK5gqEAuy1801h6CqyyJnvrecd6VB2
|
|||
|
|
|
|||
|
|
DELETE FROM t_admin_user WHERE username = 'admin';
|
|||
|
|
|
|||
|
|
INSERT INTO t_admin_user (
|
|||
|
|
id, username, password, name, email, phone, avatar_url, status,
|
|||
|
|
created_at, updated_at, deleted
|
|||
|
|
) VALUES (
|
|||
|
|
'admin001',
|
|||
|
|
'admin',
|
|||
|
|
'$2a$10$DyHiv85Fy.yoslnuxVtw/OmsK5gqEAuy1801h6CqyyJnvrecd6VB2',
|
|||
|
|
'系统管理员',
|
|||
|
|
'admin@example.com',
|
|||
|
|
'13800138000',
|
|||
|
|
NULL,
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 2. 初始化租户(幼儿园)
|
|||
|
|
-- ============================================
|
|||
|
|
DELETE FROM t_tenant WHERE code = 'KINDERGARTEN01';
|
|||
|
|
|
|||
|
|
INSERT INTO t_tenant (
|
|||
|
|
id, name, code, contact_name, contact_phone, contact_email,
|
|||
|
|
address, status, max_students, max_teachers,
|
|||
|
|
created_at, updated_at, deleted
|
|||
|
|
) VALUES (
|
|||
|
|
'tenant001',
|
|||
|
|
'阳光幼儿园',
|
|||
|
|
'KINDERGARTEN01',
|
|||
|
|
'张三',
|
|||
|
|
'13800138001',
|
|||
|
|
'contact@yangguang.com',
|
|||
|
|
'北京市朝阳区阳光路 1 号',
|
|||
|
|
'active',
|
|||
|
|
500,
|
|||
|
|
50,
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 3. 初始化教师用户
|
|||
|
|
-- ============================================
|
|||
|
|
-- 用户名:teacher1
|
|||
|
|
-- 密码:123456
|
|||
|
|
-- BCrypt 哈希:$2a$10$RmNcSVt0dBD7uYIuAcbUpuY74jTLFYo8dUOUi6NXRSf4UmGxCaxCK
|
|||
|
|
|
|||
|
|
DELETE FROM t_teacher WHERE username IN ('teacher1', 'school');
|
|||
|
|
|
|||
|
|
INSERT INTO t_teacher (
|
|||
|
|
id, tenant_id, username, password, name, phone, email,
|
|||
|
|
gender, status,
|
|||
|
|
created_at, updated_at, deleted
|
|||
|
|
) VALUES (
|
|||
|
|
'teacher001',
|
|||
|
|
'tenant001',
|
|||
|
|
'teacher1',
|
|||
|
|
-- BCrypt 加密的 "123456"
|
|||
|
|
'$2a$10$RmNcSVt0dBD7uYIuAcbUpuY74jTLFYo8dUOUi6NXRSf4UmGxCaxCK',
|
|||
|
|
'李老师',
|
|||
|
|
'13800138002',
|
|||
|
|
'teacher1@example.com',
|
|||
|
|
'female',
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
),
|
|||
|
|
(
|
|||
|
|
'school001',
|
|||
|
|
'tenant001',
|
|||
|
|
'school',
|
|||
|
|
-- BCrypt 加密的 "123456"
|
|||
|
|
'$2a$10$RmNcSVt0dBD7uYIuAcbUpuY74jTLFYo8dUOUi6NXRSf4UmGxCaxCK',
|
|||
|
|
'王校长',
|
|||
|
|
'13800138003',
|
|||
|
|
'school@example.com',
|
|||
|
|
'male',
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 4. 初始化家长用户
|
|||
|
|
-- ============================================
|
|||
|
|
-- 用户名:parent1
|
|||
|
|
-- 密码:123456
|
|||
|
|
-- BCrypt 哈希:$2a$10$RmNcSVt0dBD7uYIuAcbUpuY74jTLFYo8dUOUi6NXRSf4UmGxCaxCK
|
|||
|
|
|
|||
|
|
DELETE FROM t_parent WHERE username = 'parent1';
|
|||
|
|
|
|||
|
|
INSERT INTO t_parent (
|
|||
|
|
id, tenant_id, username, password, name, phone, email,
|
|||
|
|
gender, status,
|
|||
|
|
created_at, updated_at, deleted
|
|||
|
|
) VALUES (
|
|||
|
|
'parent001',
|
|||
|
|
'tenant001',
|
|||
|
|
'parent1',
|
|||
|
|
-- BCrypt 加密的 "123456"
|
|||
|
|
'$2a$10$RmNcSVt0dBD7uYIuAcbUpuY74jTLFYo8dUOUi6NXRSf4UmGxCaxCK',
|
|||
|
|
'张妈妈',
|
|||
|
|
'13800138004',
|
|||
|
|
'parent1@example.com',
|
|||
|
|
'female',
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 5. 初始化班级 (注意:表名是 t_clazz)
|
|||
|
|
-- t_clazz 表结构:id, tenant_id, name, grade, description, capacity, status
|
|||
|
|
-- ============================================
|
|||
|
|
DELETE FROM t_clazz WHERE name IN ('大班 1 班', '中班 1 班', '小班 1 班');
|
|||
|
|
|
|||
|
|
INSERT INTO t_clazz (
|
|||
|
|
id, tenant_id, name, grade, description, capacity, status,
|
|||
|
|
created_at, updated_at, deleted
|
|||
|
|
) VALUES (
|
|||
|
|
'class001',
|
|||
|
|
'tenant001',
|
|||
|
|
'大班 1 班',
|
|||
|
|
'大班',
|
|||
|
|
'大班 1 班',
|
|||
|
|
30,
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
),
|
|||
|
|
(
|
|||
|
|
'class002',
|
|||
|
|
'tenant001',
|
|||
|
|
'中班 1 班',
|
|||
|
|
'中班',
|
|||
|
|
'中班 1 班',
|
|||
|
|
30,
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
),
|
|||
|
|
(
|
|||
|
|
'class003',
|
|||
|
|
'tenant001',
|
|||
|
|
'小班 1 班',
|
|||
|
|
'小班',
|
|||
|
|
'小班 1 班',
|
|||
|
|
30,
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 6. 初始化学生
|
|||
|
|
-- ============================================
|
|||
|
|
DELETE FROM t_student WHERE name IN ('张小宝', '李大宝');
|
|||
|
|
|
|||
|
|
INSERT INTO t_student (
|
|||
|
|
id, tenant_id, name, gender, birth_date, grade, class_id,
|
|||
|
|
parent_name, parent_phone, status,
|
|||
|
|
created_at, updated_at, deleted
|
|||
|
|
) VALUES (
|
|||
|
|
'student001',
|
|||
|
|
'tenant001',
|
|||
|
|
'张小宝',
|
|||
|
|
'male',
|
|||
|
|
'2018-01-15',
|
|||
|
|
'大班',
|
|||
|
|
'class001',
|
|||
|
|
'张妈妈',
|
|||
|
|
'13800138004',
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
),
|
|||
|
|
(
|
|||
|
|
'student002',
|
|||
|
|
'tenant001',
|
|||
|
|
'李大宝',
|
|||
|
|
'female',
|
|||
|
|
'2019-02-20',
|
|||
|
|
'中班',
|
|||
|
|
'class002',
|
|||
|
|
'李爸爸',
|
|||
|
|
'13800138005',
|
|||
|
|
'active',
|
|||
|
|
NOW(),
|
|||
|
|
NOW(),
|
|||
|
|
0
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 7. 初始化家长 - 学生关系
|
|||
|
|
-- ============================================
|
|||
|
|
DELETE FROM t_parent_student WHERE parent_id = 'parent001';
|
|||
|
|
|
|||
|
|
INSERT INTO t_parent_student (
|
|||
|
|
id, parent_id, student_id, relationship, is_primary,
|
|||
|
|
created_at, deleted, created_by
|
|||
|
|
) VALUES (
|
|||
|
|
'ps001',
|
|||
|
|
'parent001',
|
|||
|
|
'student001',
|
|||
|
|
'parent',
|
|||
|
|
1,
|
|||
|
|
NOW(),
|
|||
|
|
0,
|
|||
|
|
'system'
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
-- ============================================
|
|||
|
|
-- 验证插入的数据
|
|||
|
|
-- ============================================
|
|||
|
|
SELECT 'Admin Users:' AS '';
|
|||
|
|
SELECT id, username, name, status FROM t_admin_user WHERE username = 'admin';
|
|||
|
|
|
|||
|
|
SELECT 'Tenants:' AS '';
|
|||
|
|
SELECT id, name, code, status FROM t_tenant WHERE code = 'KINDERGARTEN01';
|
|||
|
|
|
|||
|
|
SELECT 'Teachers:' AS '';
|
|||
|
|
SELECT id, username, name, status FROM t_teacher WHERE username IN ('teacher1', 'school');
|
|||
|
|
|
|||
|
|
SELECT 'Parents:' AS '';
|
|||
|
|
SELECT id, username, name, status FROM t_parent WHERE username = 'parent1';
|
|||
|
|
|
|||
|
|
SELECT 'Students:' AS '';
|
|||
|
|
SELECT id, name, grade, class_id, status FROM t_student WHERE name IN ('张小宝', '李大宝');
|