paperclipai/paperclip · warning
has existing tables but no migration journal. Run…
Error message
${label} has existing tables but no migration journal. Run migrations manually to sync schema. What it means
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.
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.
Example fix
# before (interactive prompt blocks deploys) # after export PAPERCLIP_MIGRATION_AUTO_APPLY=true
Defensive patterns
Strategy: validation
Validate before calling
// Refuse to boot against a journal-less non-empty database by accident.
const r = await db.execute(sql`select count(*)::int as n from information_schema.tables
where table_schema = 'public' and table_name = '__drizzle_migrations'`);
const hasJournal = r.rows[0].n > 0;
if (!hasJournal) {
throw new Error('Target DB has no migration journal; baseline it deliberately (pnpm db:migrate) or point at the right DB');
} Prevention
- 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.
When it happens
Trigger: 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'.
Common situations: Adopting a legacy database into Paperclip; staging copies made without the journal table; DBA-provisioned schemas; connecting to the wrong (non-Paperclip) shared database.
Related errors
- had drifted migration history; repaired migration journal…
- database-contract-unmet
- Migration journal has no applied revision.
- Migration journal is not a prefix of this Paperclip…
- Migration journal is not current
AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-08-18).
Data as JSON: /api/errors/86d6a9839843fb35.
Report an issue: GitHub.
Appendix: source
Thrown at server/src/index.ts:273
}
type EnsureMigrationsOptions = {
autoApply?: boolean;
};
async function ensureMigrations(
connectionString: string,
label: string,
opts?: EnsureMigrationsOptions,
): Promise<MigrationSummary> {
const autoApply = opts?.autoApply === true;
let state = await inspectMigrations(connectionString);
if (state.status === "needsMigrations" && state.reason === "pending-migrations") {
const repair = await reconcilePendingMigrationHistory(connectionString);
if (repair.repairedMigrations.length > 0) {
logger.warn(
{ repairedMigrations: repair.repairedMigrations },
`${label} had drifted migration history; repaired migration journal entries from existing schema state.`,
);
state = await inspectMigrations(connectionString);
if (state.status === "upToDate") return "already applied";
}
}
if (state.status === "upToDate") return "already applied";
if (state.status === "needsMigrations" && state.reason === "no-migration-journal-non-empty-db") {
logger.warn(
{ tableCount: state.tableCount },
`${label} has existing tables but no migration journal. Run migrations manually to sync schema.`,
);
const apply = autoApply ? true : await promptApplyMigrations(state.pendingMigrations);
if (!apply) {
throw new Error(
`${label} has pending migrations (${formatPendingMigrationSummary(state.pendingMigrations)}). ` +
"Refusing to start against a stale schema. Run pnpm db:migrate or set PAPERCLIP_MIGRATION_AUTO_APPLY=true.",
);
}View on GitHub (pinned to 3f1d897a7c)