@@ -50,6 +50,10 @@ const DEMO_PASSWORD = process.env.DEMO_PASSWORD ?? 'demo1234'
5050const DEMO_ORG_NAME = 'Reqcore Demo'
5151const DEMO_ORG_SLUG = 'reqcore-demo'
5252
53+ // Legacy values from the old applirank.com domain — cleaned up on seed
54+ const LEGACY_DEMO_EMAIL = 'demo@applirank.com'
55+ const LEGACY_ORG_SLUG = 'applirank-demo'
56+
5357// ─────────────────────────────────────────────
5458// Database connection
5559// ─────────────────────────────────────────────
@@ -358,6 +362,38 @@ function generateResponses(jobIndex: number, candidateIndex: number): Record<str
358362async function seed ( ) {
359363 console . log ( '🌱 Seeding Reqcore demo data...\n' )
360364
365+ // ─────────────────────────────────────────────
366+ // Clean up legacy applirank.com seed data
367+ // ─────────────────────────────────────────────
368+ const [ legacyOrg ] = await db
369+ . select ( { id : schema . organization . id } )
370+ . from ( schema . organization )
371+ . where ( eq ( schema . organization . slug , LEGACY_ORG_SLUG ) )
372+ . limit ( 1 )
373+
374+ const [ legacyUser ] = await db
375+ . select ( { id : schema . user . id } )
376+ . from ( schema . user )
377+ . where ( eq ( schema . user . email , LEGACY_DEMO_EMAIL ) )
378+ . limit ( 1 )
379+
380+ if ( legacyOrg || legacyUser ) {
381+ console . log ( '🧹 Removing legacy applirank.com demo data...' )
382+
383+ if ( legacyOrg ) {
384+ // All child tables (jobs, candidates, applications, members, etc.) have
385+ // onDelete: 'cascade' so deleting the org removes everything beneath it.
386+ await db . delete ( schema . organization ) . where ( eq ( schema . organization . id , legacyOrg . id ) )
387+ console . log ( ` ✅ Deleted legacy org: ${ LEGACY_ORG_SLUG } ` )
388+ }
389+
390+ if ( legacyUser ) {
391+ // sessions and accounts also cascade from the user row
392+ await db . delete ( schema . user ) . where ( eq ( schema . user . id , legacyUser . id ) )
393+ console . log ( ` ✅ Deleted legacy user: ${ LEGACY_DEMO_EMAIL } ` )
394+ }
395+ }
396+
361397 // Check if demo org already exists
362398 const existingOrg = await db
363399 . select ( )
0 commit comments