uat-seed-script

This commit is contained in:
phaichayon
2026-06-30 10:48:15 +07:00
parent e4573ac0c9
commit e12ae120b0
31 changed files with 1791 additions and 314 deletions

View File

@@ -42,11 +42,21 @@ function loadLocalEnv() {
loadEnvFile(path.resolve(process.cwd(), '.env'));
}
const ALLOW_DB_RESET_FLAG = '--allow-db-reset';
function assertSafeToReset(databaseUrl: string) {
if (process.env.ALLOW_DB_RESET !== 'true') {
throw new Error('ALLOW_DB_RESET=true is required.');
const allowDbReset =
process.env.ALLOW_DB_RESET === 'true' ||
process.argv.includes(ALLOW_DB_RESET_FLAG);
if (!allowDbReset) {
throw new Error(
`Database reset requires explicit confirmation. Run "npm run db:reset -- ${ALLOW_DB_RESET_FLAG}".`
);
}
process.env.ALLOW_DB_RESET = 'true';
if ((process.env.NODE_ENV ?? '').toLowerCase() === 'production') {
throw new Error('Database reset is blocked in NODE_ENV=production.');
}