Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

1.7 KB
Raw Blame

A migration failed in PREVIEW, how do I fix the PREVIEW database

  1. Open a new PR where you'll do the fix
  2. Go to https://vercel.com/webstudio-is/webstudio/settings/environment-variables
  3. Set APPLY_MIGRATIONS to "true" for your PR's branch
  4. Fix the failed migration code
  5. Fix the database mannually if the migration have been applied half-way
  6. Temporarily change ci:migrate script to run resolve before applying migrations: "ci:migrate": "migrations resolve rolled-back <name> --force && migrations migrate". Use applied instead of rolled-back if you manually applied the migration at previous step.
  7. Commit the changes and check Vercel logs to see if the migration is applied
  8. Change ci:migrate script back to normal
  9. Merge the PR
  10. Remove APPLY_MIGRATIONS from Vercel settings for your branch

Transacation failed with a error "Transaction API error: Transaction already closed: Could not perform operation."

Most likely reason Prisma has thrown this error is because transaction has timed out. If that's the case, you have the following options:

  1. Optimize your migration to make it faster
  2. Increase the timeout:
export default () => {
  const client = new PrismaClient();
  return client.$transaction(
    async (prisma) => {
      // migration code...
    },
    {
      timeout: 1000 * 60 * 2, // in milliseconds, default 5000
    }
  );
};
  1. Do not wrap the migration body into a transaction:
export default async () => {
  const prisma = new PrismaClient();
  // use `prisma` here without wrapping it into a transaction
};

Note that in this case if the migration fails again, it will be harder to fix the database, because the migration can end up half-way applied.