This repository was archived by the owner on Apr 13, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,21 +14,17 @@ export function ensureInitialized(db: PrismaClient): Promise<void> {
1414 if ( initPromise ) return initPromise ;
1515
1616 initPromise = ( async ( ) => {
17- // 1) Ensure admin exists (if no users at all)
18- const userCount = await db . user . count ( ) ;
19- if ( userCount === 0 ) {
20- const defaultEmail = process . env . INITIAL_ADMIN_EMAIL ?. trim ( ) . toLowerCase ( ) ?? "admin@example.com" ;
21-
22- await db . user . upsert ( {
23- where : { email : defaultEmail } ,
24- update : { role : UserRole . ADMIN } ,
25- create : {
26- email : defaultEmail ,
27- name : "Admin User" ,
28- role : UserRole . ADMIN ,
29- } ,
30- } ) ;
31- }
17+ // 1) Ensure the bootstrap admin exists (every init, no auto-provisioning outside env)
18+ const defaultEmail = process . env . INITIAL_ADMIN_EMAIL ?. trim ( ) . toLowerCase ( ) ?? "admin@example.com" ;
19+ await db . user . upsert ( {
20+ where : { email : defaultEmail } ,
21+ update : { role : UserRole . ADMIN } ,
22+ create : {
23+ email : defaultEmail ,
24+ name : "Admin User" ,
25+ role : UserRole . ADMIN ,
26+ } ,
27+ } ) ;
3228
3329 // 2) Ensure MITRE data exists
3430 const tacticCount = await db . mitreTactic . count ( ) ;
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ describe("ensureInitialized", () => {
1515 delete process . env . INITIAL_ADMIN_EMAIL ;
1616 } ) ;
1717
18- it ( "creates admin when no users and seeds MITRE when empty" , async ( ) => {
19- const user = { count : vi . fn ( ) . mockResolvedValue ( 0 ) , upsert : vi . fn ( ) } ;
18+ it ( "creates admin and seeds MITRE when empty" , async ( ) => {
19+ const user = { upsert : vi . fn ( ) } ;
2020 const mitreTactic = { count : vi . fn ( ) . mockResolvedValue ( 0 ) , upsert : vi . fn ( ) } ;
2121 const mitreTechnique = { upsert : vi . fn ( ) } ;
2222 const mitreSubTechnique = { upsert : vi . fn ( ) } ;
You can’t perform that action at this time.
0 commit comments