agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

runMigrations no longer adapts portable SQL (INTEGER→BIGINT, datetime('now')); fresh databases diverge from production

Open multiplehats opened this issue 2 months ago • 3 comments

What happens

Since 0.177.0 ("Standardize framework persistence on PostgreSQL"), runMigrations runs migration SQL verbatim. Before, adaptSqlForPostgres rewrote every string migration on Postgres: INTEGER → BIGINT, datetime('now') → CURRENT_TIMESTAMP, dropped AUTOINCREMENT.

An app that wrote its migrations in the portable subset the docs recommended now gets a different schema on a fresh database than production has:

  • epoch-millisecond columns declared INTEGER become int4 and overflow on the first insert (value "1790000000000" is out of range for type integer);
  • DEFAULT (datetime('now')) fails outright on a fresh database (local PGlite, a new preview, a test).

Existing production databases are unaffected (migrations are tracked by name and never re-run), which is what makes it easy to miss: it surfaces only on fresh databases.

The 0.177.0 changelog entry doesn't mention that the adapter is gone.

Suggestion

Either keep the rewrite for string migrations (dialect-specific { postgres } entries already bypass it), or call it out as a breaking change with the one-line app-side replacement. What we did, in the app's migration list:

const postgresMigrationSql = (sql: string) =>
  sql
    .replaceAll(/datetime\s*\(\s*'now'\s*\)/giu, "CURRENT_TIMESTAMP")
    .replaceAll(/\bAUTOINCREMENT\b/giu, "")
    .replaceAll(/\bINTEGER\b/giu, "BIGINT");

multiplehats avatar Sep 23 '26 18:09 multiplehats

Tracked in #5743.

multiplehats avatar Sep 23 '26 18:09 multiplehats

Thanks for the report. PostgreSQL migration guidance is in review at https://github.com/BuilderIO/agent-native/pull/8788; the reported incident and documentation still need verification.

builder-factory avatar Nov 05 '26 22:11 builder-factory

Thanks for the report - this is fixed by https://github.com/BuilderIO/agent-native/pull/8788, which is merged and will be on beta shortly.

builder-factory avatar Nov 19 '26 01:11 builder-factory