{"record":{"id":"3c9a2826c873c972","repo":"slopus/happy","slug":"could-not-find-prisma-migrations-directory-tried","errorCode":null,"errorMessage":"Could not find prisma/migrations directory. Tried: ${candidates.join(\", \")}","messagePattern":"Could not find prisma/migrations directory\\. Tried: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/happy-server/sources/standalone.ts","lineNumber":62,"sourceCode":"    `);\n\n    // Find migrations directory - explicit arg wins; fall back to defaults.\n    let migrationsDirResolved = \"\";\n    const candidates: string[] = [];\n    if (opts.migrationsDir) candidates.push(opts.migrationsDir);\n    candidates.push(\n        path.join(process.cwd(), \"prisma\", \"migrations\"),\n        path.join(process.cwd(), \"packages\", \"happy-server\", \"prisma\", \"migrations\"),\n        path.join(path.dirname(process.execPath), \"prisma\", \"migrations\"),\n    );\n    for (const candidate of candidates) {\n        if (fs.existsSync(candidate)) {\n            migrationsDirResolved = candidate;\n            break;\n        }\n    }\n    if (!migrationsDirResolved) {\n        throw new Error(`Could not find prisma/migrations directory. Tried: ${candidates.join(\", \")}`);\n    }\n\n    // Get all migration directories sorted\n    const dirs = fs.readdirSync(migrationsDirResolved)\n        .filter(d => fs.statSync(path.join(migrationsDirResolved, d)).isDirectory())\n        .sort();\n\n    // Get already applied migrations\n    const applied = await pg.query<{ migration_name: string }>(\n        `SELECT \"migration_name\" FROM \"_prisma_migrations\" WHERE \"finished_at\" IS NOT NULL`\n    );\n    const appliedSet = new Set(applied.rows.map(r => r.migration_name));\n\n    let appliedCount = 0;\n    for (const dir of dirs) {\n        if (appliedSet.has(dir)) {\n            continue;\n        }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-server/sources/standalone.ts#L44-L80","documentation":"runMigrations() in the standalone server searches a list of candidate paths for the prisma/migrations directory before running migrations. If none of the candidates exists on disk, it throws with the exact paths it tried, because it cannot locate the SQL migrations to apply.","triggerScenarios":"Running the standalone server from a working directory or packaged bundle (Docker image, dist folder) that does not include prisma/migrations; wrong CWD; pruning migrations in a build step.","commonSituations":"Docker images built without copying the prisma folder; running the compiled server from a different directory than the package root; monorepo builds that resolve relative to the bundle output rather than the package; npm pruning migrations via 'files' in package.json.","solutions":["Run the server from the package root so the relative prisma/migrations path resolves, or set the working directory accordingly.","Copy prisma/migrations into the image/bundle (e.g. COPY prisma ./prisma in the Dockerfile, or add 'prisma' to package.json 'files').","Set the env var/option the candidate list uses (check how candidates are built near standalone.ts:62) to point at the correct migrations path.","Verify with: ls prisma/migrations relative to where you launch the server.","If migrations are managed externally, run 'prisma migrate deploy' yourself and skip embedded migrations."],"exampleFix":"// before (Dockerfile)\nCOPY dist ./dist\nCMD [\"node\", \"dist/standalone.js\"]\n// after\nCOPY dist ./dist\nCOPY prisma ./prisma\nCMD [\"node\", \"dist/standalone.js\"]","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction migrationsExist(candidates) {\n  const found = candidates.find(c => fs.existsSync(c));\n  if (!found) {\n    throw new Error(`prisma/migrations not found. CWD=${process.cwd()}. Tried: ${candidates.join(', ')}`);\n  }\n  return found;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runMigrations();\n} catch (e) {\n  if (e.message.startsWith('Could not find prisma/migrations')) {\n    console.error('Deployment missing prisma/migrations. CWD:', process.cwd(), e.message);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Copy prisma/ (including migrations) into Docker images and published packages.","Run the server with the package root as the working directory.","Add a startup smoke test / health check that verifies the migrations dir exists.","If using package.json 'files', include 'prisma' in the whitelist."],"tags":["prisma","migrations","filesystem","deployment"],"backgroundTag":"migrations-directory-not-found","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}