fix: handle existing admin during deploy
This commit is contained in:
@@ -1387,3 +1387,4 @@ git diff --check
|
|||||||
- 生产 API 搜索 `1882120` 返回“中国移动/上海/上海”;搜索“上海”首屏响应约 80ms。
|
- 生产 API 搜索 `1882120` 返回“中国移动/上海/上海”;搜索“上海”首屏响应约 80ms。
|
||||||
- 生产 `cmpp-api`、`cmpp-gateway`、PostgreSQL、Nginx 均为 active,API health 正常。
|
- 生产 `cmpp-api`、`cmpp-gateway`、PostgreSQL、Nginx 均为 active,API health 正常。
|
||||||
- 隔离部署后曾因 `dist/assets` 被保留为 `700 root:root` 导致 Nginx 无权读取 JS/CSS、admin 页面空白;线上已修正为目录 `755`、文件 `644`,正式生产部署脚本同步固化权限。
|
- 隔离部署后曾因 `dist/assets` 被保留为 `700 root:root` 导致 Nginx 无权读取 JS/CSS、admin 页面空白;线上已修正为目录 `755`、文件 `644`,正式生产部署脚本同步固化权限。
|
||||||
|
- 正式部署发现已有生产管理员且未配置 `PROD_ADMIN_PASSWORD` 时,`upsert.create` 仍会对空密码执行哈希;已拆分 create/update 密码变量,已有账号不改密码,新建账号才生成临时密码。
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ function hashPassword(value) {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const existingUser = await prisma.user.findUnique({ where: { username } });
|
const existingUser = await prisma.user.findUnique({ where: { username } });
|
||||||
const password = configuredPassword || (existingUser ? undefined : randomBytes(18).toString('base64url'));
|
const createPassword = configuredPassword || randomBytes(18).toString('base64url');
|
||||||
|
const updatePassword = configuredPassword;
|
||||||
const role = await prisma.role.upsert({
|
const role = await prisma.role.upsert({
|
||||||
where: { code: 'platform_admin' },
|
where: { code: 'platform_admin' },
|
||||||
update: { name: '平台管理员', scope: 'platform' },
|
update: { name: '平台管理员', scope: 'platform' },
|
||||||
@@ -31,7 +32,7 @@ async function main() {
|
|||||||
update: {
|
update: {
|
||||||
email,
|
email,
|
||||||
displayName: '生产平台管理员',
|
displayName: '生产平台管理员',
|
||||||
...(password ? { passwordHash: hashPassword(password) } : {}),
|
...(updatePassword ? { passwordHash: hashPassword(updatePassword) } : {}),
|
||||||
status: 'active',
|
status: 'active',
|
||||||
failedLoginCount: 0,
|
failedLoginCount: 0,
|
||||||
lockedUntil: null,
|
lockedUntil: null,
|
||||||
@@ -42,7 +43,7 @@ async function main() {
|
|||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
displayName: '生产平台管理员',
|
displayName: '生产平台管理员',
|
||||||
passwordHash: hashPassword(password),
|
passwordHash: hashPassword(createPassword),
|
||||||
status: 'active',
|
status: 'active',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -56,7 +57,9 @@ async function main() {
|
|||||||
'CMPP production admin account',
|
'CMPP production admin account',
|
||||||
`username=${username}`,
|
`username=${username}`,
|
||||||
`email=${email}`,
|
`email=${email}`,
|
||||||
password ? `password=${password}` : 'password=unchanged',
|
existingUser
|
||||||
|
? (updatePassword ? `password=${updatePassword}` : 'password=unchanged')
|
||||||
|
: `password=${createPassword}`,
|
||||||
`generatedAt=${new Date().toISOString()}`,
|
`generatedAt=${new Date().toISOString()}`,
|
||||||
'',
|
'',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@@ -65,7 +68,7 @@ async function main() {
|
|||||||
}
|
}
|
||||||
console.log(`Production admin is ready: ${email}`);
|
console.log(`Production admin is ready: ${email}`);
|
||||||
if (!credentialFile) {
|
if (!credentialFile) {
|
||||||
console.log(`Temporary password: ${password}`);
|
console.log(existingUser && !updatePassword ? 'Password unchanged' : `Temporary password: ${existingUser ? updatePassword : createPassword}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user