Vercel
Reylo Migrate on Vercel
Migrate production as the build's last step:
{
"scripts": {
"vercel-build": "reylo migrate deploy && next build && reylo migrate deploy --url \"$DATABASE_URL_UNPOOLED\""
}
}Vercel runs this script unless your project sets a Build Command. Nothing of yours runs between the build and going live, and a build or migration that fails stops the deploy.
Database
A migration needs your database's direct connection string. Neon's Vercel integration sets it as DATABASE_URL_UNPOOLED, in each environment, and can create a branch for each preview deployment.
Build database
The build reads your schema before production has it. So point it at a database of its own, such as a Neon branch:
direct_url: ${BUILD_DATABASE_URL:-${DATABASE_URL_UNPOOLED:-${DATABASE_URL}}}Set BUILD_DATABASE_URL in the Production environment only, to that database's direct connection string. A preview build reads its own database, which the script migrates first.
A migration can reach that database and then fail on production. Reset the branch from its parent before you change the migration:
$ neon branches reset build --parentPages the build prerenders still query production, before it's migrated. Render a page that reads a new column on each request.