feat: multi-module iteration
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import '../src/load-env';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { hashPassword } from '../src/common/crypto/password.util';
|
||||
|
||||
const LOGIN_NAME = process.env.SUPER_ADMIN_LOGIN ?? 'admin';
|
||||
const PASSWORD = process.env.SUPER_ADMIN_PASSWORD ?? 'dukang@123!';
|
||||
const PLACEHOLDER_PHONE = process.env.SUPER_ADMIN_PHONE ?? '19900000001';
|
||||
|
||||
async function main() {
|
||||
const prisma = new PrismaClient();
|
||||
const passwordHash = hashPassword(PASSWORD);
|
||||
try {
|
||||
const deleted = await prisma.$executeRaw`
|
||||
DELETE FROM hq_account WHERE admin_role = 'SUPER_ADMIN'
|
||||
`;
|
||||
console.log(`Deleted ${deleted} SUPER_ADMIN account row(s).`);
|
||||
|
||||
await prisma.$executeRaw`
|
||||
INSERT INTO hq_account (
|
||||
phone, login_name, password_hash, name, admin_role, status, created_at, updated_at
|
||||
) VALUES (
|
||||
${PLACEHOLDER_PHONE},
|
||||
${LOGIN_NAME},
|
||||
${passwordHash},
|
||||
${'超级管理员'},
|
||||
${'SUPER_ADMIN'},
|
||||
${'ACTIVE'},
|
||||
NOW(3),
|
||||
NOW(3)
|
||||
)
|
||||
`;
|
||||
|
||||
console.log('Created SUPER_ADMIN:', {
|
||||
loginName: LOGIN_NAME,
|
||||
phone: PLACEHOLDER_PHONE,
|
||||
password: '(hidden)',
|
||||
});
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user