---
title: Database migrations
description: "Learn how database migrations work on your B12 website: when the AI Agent creates them, how pending migrations run, and how to undo a change."
---

[Skip to content](https://support.b12.io/en/v3/database-migrations#main-content)

[![2026 B12 company logo.](https://support.b12.io/hubfs/B12_logo.svg)](https://support.b12.io/en?hsLang=en)

- [B12 Website](https://www.b12.io/)
- Products
  
  Show submenu for Products

    - Sites
      
      Show submenu for Sites

          - [AI builder](https://www.b12.io/ai-website-builder)
          - [Backends](https://www.b12.io/backends)
    - Client engagement
      
      Show submenu for Client engagement

          - [Client intake forms](https://www.b12.io/client-intake-forms)
          - [Contact manager](https://www.b12.io/contact-manager)
- [Templates](https://www.b12.io/ai-website-prompt-gallery)
- Resources
  
  Show submenu for Resources

    - [Resource center](https://www.b12.io/resource-center)
    - [Case studies](https://www.b12.io/case-studies)
- [Pricing](https://www.b12.io/pricing)
- [Log in](https://b12.io/dashboard/)

Open main navigation

Close main navigation

- [B12 Website](https://www.b12.io/)
- Products
  
  Show submenu for Products

    - Sites
      
      Show submenu for Sites

          - [AI builder](https://www.b12.io/ai-website-builder)
          - [Backends](https://www.b12.io/backends)
    - Client engagement
      
      Show submenu for Client engagement

          - [Client intake forms](https://www.b12.io/client-intake-forms)
          - [Contact manager](https://www.b12.io/contact-manager)
- [Templates](https://www.b12.io/ai-website-prompt-gallery)
- Resources
  
  Show submenu for Resources

    - [Resource center](https://www.b12.io/resource-center)
    - [Case studies](https://www.b12.io/case-studies)
- [Pricing](https://www.b12.io/pricing)
- [Log in](https://b12.io/dashboard/)
- [Start for free](https://b12.io/signup/)

[Start for free](https://b12.io/signup/)

 How can we help?

- There are no suggestions because the search field is empty.

1. [B12 Help Center](https://support.b12.io/en?hsLang=en)
2. [Built-in features](https://support.b12.io/en/built-in-features?hsLang=en)
3. [Backends](https://support.b12.io/en/built-in-features?hsLang=en#backends)

# Database migrations

## Learn how the AI Agent changes your site's database and how to reverse a change you don't want.

| ![ronnel](https://support.b12.io/hs-fs/hubfs/Ronnel%20DG.png?width=60&height=60&name=Ronnel%20DG.png) Written by: Ronnel DG Last updated: 01 Dec., 2026 |
| --- |

A database migration is a saved set of instructions that changes your website's database. A database is an organized store of your site's information, such as member sign-ups, orders, blog posts, or uploaded photos. Whenever you ask for a change to that information or how it's stored, the AI Agent writes a migration and carries it out.

**Note:** Migrations only apply to websites with **Backends** turned on. Backends is B12's optional feature for storing data, user accounts, and uploaded files. If your site doesn't use Backends, it has no migrations.

### What a migration is

Picture your database as a set of spreadsheets. Each spreadsheet is a table (for example, a Members table), and each column holds one kind of information (name, email, join date).

A migration is like a work order you'd hand a contractor: "Add a Members table with columns for name and email," or "Add a phone number column to Members." The AI Agent writes the work order, then carries it out.

You'll see these terms in the AI Agent's replies:

- **Apply (or run):** to carry out a migration's instructions on your live database.
- **Applied:** a migration that has already run. Its changes are in your database.
- **Pending:** a migration that's saved but hasn't run yet.
- **Schema:** the layout of your database (which tables and columns exist), as opposed to the information stored in them.
- **Access rules:** settings that control who can see or change each table, such as "visitors can read published posts, but only you can edit them." You might also see these called RLS policies (short for row level security).

Each migration is saved as a file in your site's code. To see them, click `Code` in the toolbar above the website preview, then open the **supabase** folder and its **migrations** folder. Each file name starts with the date and time it was created (for example, `20261103143000_create_members.sql`), which keeps migrations in order.

![Code view file list with the supabase folder and its migrations folder open, showing dated migration files](https://support.b12.io/hs-fs/hubfs/image-png-Nov-30-2026-08-47-16-9093-PM.png?width=300&height=368&name=image-png-Nov-30-2026-08-47-16-9093-PM.png)

### When the AI Agent creates a migration

The AI Agent creates a migration whenever your request changes the database. You don't need to ask for one by name. Common examples:

- **Storing something new:** "Let visitors save favorite recipes" creates a Favorites table.
- **Changing what's stored:** "Save a phone number when people sign up" adds a column.
- **Changing who can see or edit data:** "Only I should be able to edit blog posts" updates the access rules.
- **Accepting uploads:** "Let members upload a profile photo" creates a storage area for those files (called a bucket).
- **Changing the information itself:** "Add these 10 products," "Mark every order before June as shipped," or "Delete the test orders." The AI Agent makes one-time data changes with migrations too, so every change it makes has a record.

![AI Agent reply to "Let members upload a profile photo," saying it applied the database and storage setup](https://support.b12.io/hs-fs/hubfs/image-png-Nov-30-2026-08-47-41-2650-PM.png?width=300&height=481&name=image-png-Nov-30-2026-08-47-41-2650-PM.png)

**Tip:** For a quick fix to a few rows, you can also edit your data by hand in `Backends` \> `Database`. Changes you make there don't create migrations.

### When a migration takes effect

The AI Agent writes a migration and applies it in the same step. Your live database changes as soon as the AI Agent finishes.

**Caution:** Database changes don't wait for you to publish. They affect your live site right away. Before a change that deletes or edits existing information, ask the AI Agent to show you the plan first.

When you ask for a preview, the AI Agent describes the change in the chat and doesn't save or run anything until you approve it.

**To review a database change before it happens:**

1. Copy this prompt into the AI Agent chat and replace the bracketed text:
   
   ```
   Before changing anything, show me the database change you'd make to [describe what you want]. Don't apply it yet.
   ```
2. Read the plan in the AI Agent's reply.
3. When you're happy with it, reply "Go ahead and apply it"**.**

Database changes only happen in a live chat. Scheduled tasks (under `Agent` \> `Schedule`) can't create or apply migrations.

### How pending migrations run

When the AI Agent applies migrations, it runs every pending migration, oldest first. It can't choose to run only some of them. This matters if a migration was left pending, for example one that failed, or one the AI Agent saved but didn't get to apply because the chat was stopped or hit an error.

Before saving a new database change, the AI Agent checks for pending migrations. If it finds one, it tells you which migration is pending and asks whether to apply it first, fix it, or remove it. A pending migration has never run, so removing it doesn't change your database.

![AI Agent reply saying a failed migration is still pending and asking whether to pause the new change or remove it](https://support.b12.io/hs-fs/hubfs/image-png-Nov-30-2026-08-43-39-2704-PM.png?width=300&height=312&name=image-png-Nov-30-2026-08-43-39-2704-PM.png)

If one migration fails, the AI Agent stops there. A failed migration makes no changes to your database. Migrations that ran before it stay applied, while the failed migration and any after it stay pending.

### Undoing or fixing a migration

An applied migration can't be un-run or deleted. Deleting or editing its file doesn't change your database either, because B12 records the migration as applied and won't run it again.

Instead, you undo a change with a new migration that reverses or corrects the earlier one. For example:

- **An unwanted column:** a new migration removes it.
- **A table made public by mistake:** a new migration tightens its access rules.
- **A table you no longer need:** a new migration removes the table and the information in it.

To undo a change, describe what went wrong and what you want instead:

```
Your last database change [describe what it did, for example added a "nickname" column to Members] isn't what I wanted. Undo it with a new migration so that [describe the result you want].
```

![AI Agent reply to an undo request, confirming a new migration removed the nickname column](https://support.b12.io/hs-fs/hubfs/image-png-Nov-30-2026-08-48-05-8829-PM.png?width=300&height=481&name=image-png-Nov-30-2026-08-48-05-8829-PM.png)

**Warning:** Restoring a previous version of your site doesn't undo database changes. Versions cover your site's pages and code, including the migration files, but not the information in your database. If you restore to before a change, that change's migration file disappears from your code, but the change stays in your database. B12 doesn't currently offer self-serve database backup or restore, so removing a table or column deletes the information in it for good.

#### Making an old migration harmless

Sometimes you'll want an old migration to stop mattering, for example one written for a feature you've since dropped. Because applied migrations can't be deleted, ask the AI Agent for a new migration that cancels out everything the old one did. The old one stays in your site's history but no longer has any effect.

### Tips for database changes

These habits keep database changes predictable:

- **Make one database change per prompt.** Smaller changes are easier to check and to reverse.
- **Ask for a preview before anything that deletes information.** Deleted information can't be recovered.
- **Test right after a change.** Try the feature on your site (sign up, submit, upload) before moving on.
- **Describe the outcome you want.** "Only logged-in members can see the directory" is enough. The AI Agent handles the technical details.

### Frequently asked questions

→Can I choose which pending migrations to apply?

⇒No. Applying always runs every pending migration, oldest first. If there's one you don't want, ask the AI Agent to remove or fix it before anything is applied.

→Can I delete a migration?

⇒Only one that hasn't run yet. An applied migration stays in your site's history permanently. To reverse its effect, ask the AI Agent for a new migration that undoes it.

→Does publishing my site apply or undo migrations?

⇒No. Migrations change your database when they're applied, whether or not you publish. Publishing updates your site's pages.

→I edited an old migration file in the code editor. Why didn't anything change?

⇒B12 runs each migration only once, so editing one that's already applied has no effect. Ask the AI Agent to make the change with a new migration. Don't ask the AI Agent to rename a migration file either. B12 tracks migrations by name, so a renamed file runs again.

### Next steps

- [Adding backend functionality](https://support.b12.io/en/v3/adding-backend-functionality?hsLang=en)
- [Restoring a previous version of your website](https://support.b12.io/en/v3/restoring-a-previous-version-of-your-website?hsLang=en)

- [Getting started](https://support.b12.io/en/getting-started?hsLang=en#main-content)

    - [Introduction](https://support.b12.io/en/getting-started?hsLang=en#introduction)
    - [Detailed guides](https://support.b12.io/en/getting-started?hsLang=en#detailed-guides)
- [Working with B12's AI Agent](https://support.b12.io/en/working-with-b12s-ai-agent?hsLang=en#main-content)

    - [Agent Skills](https://support.b12.io/en/working-with-b12s-ai-agent?hsLang=en#agent-skills)
    - [Prompting basics](https://support.b12.io/en/working-with-b12s-ai-agent?hsLang=en#prompting-basics)
    - [Tasks & automation](https://support.b12.io/en/working-with-b12s-ai-agent?hsLang=en#tasks-automation)
- [Built-in features](https://support.b12.io/en/built-in-features?hsLang=en#main-content)

    - [Visual edit](https://support.b12.io/en/built-in-features?hsLang=en#visual-edit)
    - [Code editor](https://support.b12.io/en/built-in-features?hsLang=en#code-editor)
    - [Backends](https://support.b12.io/en/built-in-features?hsLang=en#backends)
    - [Forms & submissions](https://support.b12.io/en/built-in-features?hsLang=en#forms-submissions)
    - [Commerce](https://support.b12.io/en/built-in-features?hsLang=en#commerce)
    - [Contact manager](https://support.b12.io/en/built-in-features?hsLang=en#contact-manager)
    - [eSignatures](https://support.b12.io/en/built-in-features?hsLang=en#esignatures)
    - [Email Marketing](https://support.b12.io/en/built-in-features?hsLang=en#email-marketing)
    - [Team](https://support.b12.io/en/built-in-features?hsLang=en#team)
    - [Analytics](https://support.b12.io/en/built-in-features?hsLang=en#analytics)
    - [Website settings](https://support.b12.io/en/built-in-features?hsLang=en#website-settings)
- [Adding functionality](https://support.b12.io/en/adding-functionality?hsLang=en#main-content)

    - [Third-party integrations](https://support.b12.io/en/adding-functionality?hsLang=en#third-party-integrations)
    - [Scheduling & Productivity Integrations](https://support.b12.io/en/adding-functionality?hsLang=en#scheduling-productivity-integrations)
    - [Multimedia Integrations](https://support.b12.io/en/adding-functionality?hsLang=en#multimedia-integrations)
    - [Membership & Portal Integrations](https://support.b12.io/en/adding-functionality?hsLang=en#membership-portal-integrations)
    - [Pages & site features](https://support.b12.io/en/adding-functionality?hsLang=en#pages-site-features)
    - [Images & media](https://support.b12.io/en/adding-functionality?hsLang=en#images-media)
- [Publishing & growing](https://support.b12.io/en/publishing-growing?hsLang=en#main-content)

    - [Connecting your Domain](https://support.b12.io/en/publishing-growing?hsLang=en#connecting-your-domain)
    - [Domains FAQ](https://support.b12.io/en/publishing-growing?hsLang=en#domains-faq)
    - [Email Forwarding & Sending](https://support.b12.io/en/publishing-growing?hsLang=en#email-forwarding-sending)
    - [Growth & Marketing](https://support.b12.io/en/publishing-growing?hsLang=en#growth-marketing)
    - [Hosting](https://support.b12.io/en/publishing-growing?hsLang=en#hosting)
- [Troubleshooting](https://support.b12.io/en/troubleshooting?hsLang=en#main-content)

    - [FAQs](https://support.b12.io/en/troubleshooting?hsLang=en#faqs)
    - [Common issues](https://support.b12.io/en/troubleshooting?hsLang=en#common-issues)
- [Account & billing](https://support.b12.io/en/account-billing?hsLang=en#main-content)

    - [Account Login & Password](https://support.b12.io/en/account-billing?hsLang=en#account-login-password)
    - [Payments & cancellation](https://support.b12.io/en/account-billing?hsLang=en#payments-cancellation)
    - [Your Account](https://support.b12.io/en/account-billing?hsLang=en#your-account)
    - [Managing Multiple Websites](https://support.b12.io/en/account-billing?hsLang=en#managing-multiple-websites)
    - [Multi-user](https://support.b12.io/en/account-billing?hsLang=en#multi-user)
    - [Plans & pricing](https://support.b12.io/en/account-billing?hsLang=en#plans-pricing)
- [Getting support](https://support.b12.io/en/getting-support?hsLang=en#main-content)

    - [Professional & Advanced Plan Support (B12 2.0)](https://support.b12.io/en/getting-support?hsLang=en#professional-advanced-plan-support-b12-2-0)
- [B12 2.0](https://support.b12.io/en/b12-2-0?hsLang=en#main-content)

    - [Website Structure and Content](https://support.b12.io/en/b12-2-0?hsLang=en#website-structure-and-content)
    - [Website Style & Design](https://support.b12.io/en/b12-2-0?hsLang=en#website-style-design)
    - [Sitewide Settings](https://support.b12.io/en/b12-2-0?hsLang=en#sitewide-settings)
    - [Using the B12 Editor](https://support.b12.io/en/b12-2-0?hsLang=en#using-the-b12-editor)
    - [Analytics & SEO](https://support.b12.io/en/b12-2-0?hsLang=en#analytics-seo)
    - [Integrations - General](https://support.b12.io/en/b12-2-0?hsLang=en#integrations-general)
    - [Integrations - Communication](https://support.b12.io/en/b12-2-0?hsLang=en#integrations-communication)
    - [Integrations - Language](https://support.b12.io/en/b12-2-0?hsLang=en#integrations-language)
    - [Integrations - Ecommerce](https://support.b12.io/en/b12-2-0?hsLang=en#integrations-ecommerce)
    - [Professional & Advanced Plan Features](https://support.b12.io/en/b12-2-0?hsLang=en#professional-advanced-plan-features)
    - [Troubleshooting & Resources](https://support.b12.io/en/b12-2-0?hsLang=en#troubleshooting-resources)
    - [Contact Forms](https://support.b12.io/en/b12-2-0?hsLang=en#contact-forms)
    - [Online Scheduling](https://support.b12.io/en/b12-2-0?hsLang=en#online-scheduling)
    - [Advanced Editing (Experts Only)](https://support.b12.io/en/b12-2-0?hsLang=en#advanced-editing-experts-only)

[![B12\_logo\_2025](https://support.b12.io/hs-fs/hubfs/B12_logo_2025.png?width=53&height=24&name=B12_logo_2025.png "B12_logo_2025")](https://www.b12.io)

© 2025 B12. All rights reserved.

<https://twitter.com/b12> <https://www.facebook.com/B12io> <https://www.youtube.com/@b12io> <https://www.instagram.com/b12io>

×