2026-08-17 12:25:42 +08:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2026-10-14 10:22:53 +08:00
|
|
|
|
// 初始管理员账号。
|
|
|
|
|
|
// 口令:下方内置 bcrypt 哈希仅为**开发/演示**默认值(对应公开弱口令,仅供本机初始化)。
|
|
|
|
|
|
// 正式初始化(生产等)时应通过环境变量 ADMIN_INIT_PASSWORD 注入真实口令 ——
|
|
|
|
|
|
// 本文件⛔不落盘任何明文口令(铁律 25)。
|
2026-10-14 10:47:51 +08:00
|
|
|
|
//
|
|
|
|
|
|
// ⚠️ 【R111 更正 · 实测】本 seeder 原先 `bulkInsert` 到 **`accounts`** 表(row 含
|
|
|
|
|
|
// role/name_cn/salt/id_number 等列);但登录链路读的是 **`admins`** 表
|
|
|
|
|
|
// (`service/auth.js:101 findAdmin()` → `model/admin.js:49 tableName='admins'`)
|
|
|
|
|
|
// ⇒ 原写法属**死写入**(种下的那行永远不会被登录读取)。
|
|
|
|
|
|
// 已改为写入 `admins`,并按该表真实列契约(`id/username/password/created_at/updated_at`,
|
|
|
|
|
|
// 见 `database/migrations/002-create-admins.js:17-46` 与 `database/schema.sql:20-29`)重写 row。
|
|
|
|
|
|
// 详见 `.workbuddy/memory/BACKLOG.md` 候选⑳。
|
2026-08-17 12:25:42 +08:00
|
|
|
|
module.exports = {
|
|
|
|
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
const now = new Date();
|
2026-10-14 10:47:51 +08:00
|
|
|
|
// `admins` 表列契约:id(自增主键,勿传)/ username / password / created_at / updated_at。
|
|
|
|
|
|
// ⛔ 该表**无** salt / role / name_cn / id_number / activated / score 等列。
|
2026-10-14 10:22:53 +08:00
|
|
|
|
const row = {
|
2026-10-14 10:47:51 +08:00
|
|
|
|
username: 'admin',
|
|
|
|
|
|
// bcrypt(cost=10) 哈希 = 开发默认弱口令(公开值,仅供本机初始化;生产须经 ADMIN_INIT_PASSWORD 覆盖)。
|
|
|
|
|
|
// 60 字符 < `admins.password VARCHAR(100)` ⇒ 列宽容得下。
|
2026-10-14 10:22:53 +08:00
|
|
|
|
password: '$2b$10$Nc6PCJItIwuOzpM22dTiAezB.jZMI8mzkCbg3oRZkAWx.QaI4co9.',
|
|
|
|
|
|
created_at: now,
|
|
|
|
|
|
updated_at: now,
|
|
|
|
|
|
};
|
2026-10-14 10:47:51 +08:00
|
|
|
|
// 若提供 ADMIN_INIT_PASSWORD,则以之为准重算 bcrypt 哈希(明文只经过程环境,⛔ 不落盘)。
|
2026-10-14 10:22:53 +08:00
|
|
|
|
const initPwd = process.env.ADMIN_INIT_PASSWORD;
|
|
|
|
|
|
if (initPwd) {
|
2026-10-14 10:47:51 +08:00
|
|
|
|
row.password = require('bcrypt').hashSync(String(initPwd), 10);
|
2026-10-14 10:22:53 +08:00
|
|
|
|
}
|
2026-10-14 10:47:51 +08:00
|
|
|
|
await queryInterface.bulkInsert('admins', [row], {});
|
2026-08-17 12:25:42 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
2026-10-14 10:47:51 +08:00
|
|
|
|
await queryInterface.bulkDelete('admins', {
|
|
|
|
|
|
username: 'admin',
|
2026-08-17 12:25:42 +08:00
|
|
|
|
}, {});
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|