{"record":{"id":"86d6a9839843fb35","repo":"paperclipai/paperclip","slug":"label-has-existing-tables-but-no-migration-jour","errorCode":null,"errorMessage":"${label} has existing tables but no migration journal. Run migrations manually to sync schema.","messagePattern":"(.+?) has existing tables but no migration journal\\. Run migrations manually to sync schema\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/index.ts","lineNumber":218,"sourceCode":"    label: string,\n    opts?: EnsureMigrationsOptions,\n  ): Promise<MigrationSummary> {\n    const autoApply = opts?.autoApply === true;\n    let state = await inspectMigrations(connectionString);\n    if (state.status === \"needsMigrations\" && state.reason === \"pending-migrations\") {\n      const repair = await reconcilePendingMigrationHistory(connectionString);\n      if (repair.repairedMigrations.length > 0) {\n        logger.warn(\n          { repairedMigrations: repair.repairedMigrations },\n          `${label} had drifted migration history; repaired migration journal entries from existing schema state.`,\n        );\n        state = await inspectMigrations(connectionString);\n        if (state.status === \"upToDate\") return \"already applied\";\n      }\n    }\n    if (state.status === \"upToDate\") return \"already applied\";\n    if (state.status === \"needsMigrations\" && state.reason === \"no-migration-journal-non-empty-db\") {\n      logger.warn(\n        { tableCount: state.tableCount },\n        `${label} has existing tables but no migration journal. Run migrations manually to sync schema.`,\n      );\n      const apply = autoApply ? true : await promptApplyMigrations(state.pendingMigrations);\n      if (!apply) {\n        throw new Error(\n          `${label} has pending migrations (${formatPendingMigrationSummary(state.pendingMigrations)}). ` +\n            \"Refusing to start against a stale schema. Run pnpm db:migrate or set PAPERCLIP_MIGRATION_AUTO_APPLY=true.\",\n        );\n      }\n  \n      logger.info({ pendingMigrations: state.pendingMigrations }, `Applying ${state.pendingMigrations.length} pending migrations for ${label}`);\n      await applyPendingMigrations(connectionString);\n      return \"applied (pending migrations)\";\n    }\n  \n    const apply = autoApply ? true : await promptApplyMigrations(state.pendingMigrations);\n    if (!apply) {","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/index.ts#L200-L236","documentation":"The target database has tables but no drizzle migration journal — the schema was created outside the migration system. The server warns, then either auto-applies migrations (PAPERCLIP_MIGRATION_AUTO_APPLY=true), prompts interactively, or — if you decline — refuses to start against a possibly stale schema. The warning itself is the pre-prompt notice; declining escalates to a thrown error.","triggerScenarios":"Pointing the server at a manually-created database, a schema-only restored dump, or a DB provisioned by external tooling that never ran drizzle migrations — inspectMigrations returns reason 'no-migration-journal-non-empty-db'.","commonSituations":"Adopting a legacy database into Paperclip; staging copies made without the journal table; DBA-provisioned schemas; connecting to the wrong (non-Paperclip) shared database.","solutions":["Confirm the database is genuinely meant to be Paperclip's; if it is a stranger DB, fix the connection string first.","Let migrations apply: answer yes at the prompt or set PAPERCLIP_MIGRATION_AUTO_APPLY=true.","Baseline manually by running `pnpm db:migrate` against the database to sync schema and journal.","Never run Paperclip against an unrelated shared database."],"exampleFix":"# before (interactive prompt blocks deploys)\n# after\nexport PAPERCLIP_MIGRATION_AUTO_APPLY=true","handlingStrategy":"validation","validationCode":"// Refuse to boot against a journal-less non-empty database by accident.\nconst r = await db.execute(sql`select count(*)::int as n from information_schema.tables\n  where table_schema = 'public' and table_name = '__drizzle_migrations'`);\nconst hasJournal = r.rows[0].n > 0;\nif (!hasJournal) {\n  throw new Error('Target DB has no migration journal; baseline it deliberately (pnpm db:migrate) or point at the right DB');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provision Paperclip databases only through its own migration flow.","For adopted/baselined DBs, document the baseline procedure and run it once, deliberately.","Set PAPERCLIP_MIGRATION_AUTO_APPLY=true only in pipelines where auto-apply is intended.","Guard connection strings so the server can never start against an unrelated shared database."],"tags":["database","migrations","journal","startup","schema"],"backgroundTag":"missing-migration-journal","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}