VicroCode
Make Code Create Value
VicroCode is a lightweight online platform for publishing, running, sharing, and monetizing code projects. Launch HTML, Python, SQLite, AI agents, management tools, games, and more without server setup.
Please wait while VicroCode loads. You can also explore the AI programming guide
Loading...

AI MARKET GUIDE

A migration-rehearsal gate so a bad schema change can't crash-loop your SQLite app

A defined-but-never-called function made a UNIQUE index migration crash on every boot. Here's how to rehearse a migration on a DB copy before it ever touches production.

The Mareo incident is the kind of thing you only really understand after it happens to you, so let me walk through it the way I'd tell a colleague over coffee.

Mareo is a desktop agent (DeepSeek Harness wrapped in an Electron shell) that, by the author's own account, had grown to around 60 real users, with one account sending over ten thousand requests and still doing two thousand-plus in a single day. Small, but genuinely in production. Then came the invite feature. Adding it meant one new column and one index. The migration looked innocent:

function migrate(db) {
  db.exec(SCHEMA) // SCHEMA contains CREATE UNIQUE INDEX on users(inviteCode)
  addUsageColumns(db)
}

The trap: the `SCHEMA` string included `CREATE UNIQUE INDEX idx_users_inviteCode ON users(inviteCode) WHERE inviteCode IS NOT NULL`, but the `inviteCode` column was supposed to be created by `addUserColumns(db)`. That function was defined. Nobody called it. So on an existing database, boot hit `no such column: inviteCode`, the process exited, the restart policy brought it straight back up, and it failed again. Fifteen loops. The API returned 502 for ten minutes.

The detail that makes it sting: the author's own model calls went through the same gateway, so when it went down he'd also lost the tool he'd normally use to fix it. He ended up leaning on codex to get out.

What is the signal underneath this?

If you read around the same corner of the community, this isn't an isolated horror story. You see a one-person agent with paying users, a cross-border seller who now wants a lean AI-assisted team, a remote job ad built entirely around "do more with fewer people and AI tooling." The common thread is that solo builders and tiny teams are running real production systems, writing them partly with AI, and carrying all the operational risk themselves.

That changes which bug hurts most. When you're the whole team, the migration that takes down the app is also the migration that takes down the thing you'd use to diagnose it. A green test suite is not reassurance here. Mareo had 155 passing tests. Every one of them built a fresh database and ran down the clean-install path, so not a single test ever exercised "existing database gets upgraded." The one path that mattered in production was the one path nobody tested.

What was the durable fix?

The author's own post-mortem lands on three changes. First, rehearse before deploy: copy the production database with `VACUUM INTO` and run the migration against that copy in isolation first, so a failure stops there and production isn't touched. Second, dual-slot switching: bring the new instance up on another port, health-check it against real data reads, and only then repoint nginx. Third, migrations must have a test that covers the upgrade path, not just the fresh-install path.

The second one (the port/nginx slot swap) and the Docker restart-policy behavior that turned one failure into a fifteen-boot loop are infrastructure concerns. **I'm keeping them explicitly out of scope here, because they fall outside what VicroCode provides. VicroCode doesn't give you container restart policies, a second port, or an nginx front door to flip. If you need dual-slot cutover, that lives on your own infrastructure.**

What VicroCode *can* carry cleanly is the first idea, the rehearsal gate, which is also the one that would have caught this exact bug. That's the part worth rebuilding.

How do you rebuild the rehearsal gate?

The shape is simple: never run an untested migration against the only copy of your data. Run it against a throwaway copy first, prove it comes out clean, and only then decide to promote.

**Step one, work on a copy, never the original.** Keep your live SQLite database as a file in the project, and before anything else, make a byte-for-byte copy as a separate database file through file management. The rehearsal always targets the copy. If the migration detonates, it detonates on a disposable file and the live one is untouched.

**Step two, run the migration in isolation.** Put your migration logic into a script and run Python online against the copied database. This is where the Mareo bug would have surfaced immediately: executing the real `migrate` sequence against a database that already has rows, not a freshly created one. The run either completes or it raises `no such column: inviteCode`, and either way it's happening on the copy. After the migration runs, the same script should do the checks a fresh-install test would never think to do: confirm the new column exists, confirm the index was created, and run the couple of queries the app actually issues on boot, so a column-ordering or constraint problem shows up as a failed assertion rather than a 2 a.m. page.

**Step three, eyeball the result when an assertion isn't enough.** For the cases where you want to actually look at the migrated schema and a few rows, open the copy in the SQLite editor and check the table definition and the index by hand. This is useful the first few times you build a gate like this, before you trust the assertions to catch everything.

**Step four, read pass/fail on a small board.** Have the Python run write its outcome (clean pass, or which check failed and the error text) to a small results file or table, and put a lightweight status page in front of it that you run HTML online. Nothing fancy, just the last run's verdict, the failing assertion if any, and a timestamp. The point is that "is this migration safe to promote?

becomes a thing you glance at, not a thing you infer from logs after it's already looping.

Promotion, in this scoped version, is a decision you make once the board is green: you apply the migration to the real file. That's the deliberate boundary. The gate's job is to make sure you never make that decision blind. The automated cutover and rollback that the original post describes stay on your own infrastructure.

What trade-offs should you know up front?

Copying the database each time costs time and space, and for a large database that's not free; it's the price of touching a copy instead of the original, and for most solo-scale apps it's cheap enough to always pay. The gate also only tests what you tell it to, so if your assertions mirror the same fresh-install assumptions that fooled the original 155 tests, you'll get a green board and still ship the bug. The whole value is in copying *real, already-populated* data and checking the queries that run on an *upgraded* database, not a new one.

And this gate does not restart anything, reroute traffic, or roll back a live deploy. It answers one question honestly before you touch production, which is exactly the question that went unasked the night a defined-but-never-called function looped a process fifteen times. Whether it would have fully prevented that specific outage in a real deployment is unverified; I'm describing the design intent, not a measured result.

FAQ

Why do bad migrations crash-loop an app?

Because the new code starts before the schema is compatible, so every restart hits the same error and the loop never exits.

What does a rehearsal gate do?

Applies the migration to a throwaway copy, runs the critical queries, and only then touches production.

What does it cost?

A few extra minutes per release and one more step that can fail. That is the point.

Further reading