Resolving IndexedDB Migrations #83
Replies: 2 comments 4 replies
-
Looks like it could be implemented, though maybe a little complicated. Anyway this sounds great! |
Beta Was this translation helpful? Give feedback.
-
Each customer is assigned a Guid. I would like to be able to make a separate DB of that customer identified by their Guid. 1.) Are you deploying new databases with pre-made tables? Yes, each DB will have all the same tables/fields Let me know if you need more clarification. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Table-First Migration System - (Snapshot-Based Versioning)
I'm starting this new discussion thread as I'd like to move out of the
alpha
stage when both of the following is confirmed:1.) General confidence in stability.
2.) The migration system is complete.
So, I'd like to propose the architecture I want to introduce to bring this project to its final form.
The Core Philosophy: Table-First Thinking
Unlike relational databases, IndexedDB stores are isolated and non-relational. Yet most migration tooling still thinks in terms of full database versioning, which doesn’t match the reality of how IndexedDB actually behaves.
So here’s the foundational shift:
In IndexedDB, updating a “database version” is just a means to an end—it’s only there to update object stores (tables). The goal is not to upgrade the DB, but to bring each table to its correct state. That’s where this new system begins.
How It Works (High-Level Overview)
Each Table Has Its Own Version
We treat tables as isolated, trackable units. Their version history is controlled independently, stored in an internal tracking table.
Snapshots Represent Each Version
A CLI tool (powered by the Magic Scaffolding Protocol) creates table snapshots, which capture the schema state of a table at a given version.
Diffs Drive Migrations
When a new snapshot is generated, the system compares it to the previous version and auto-generates migration steps. For common operations (like added fields or indexes), it scaffolds automatically.
Manual Conflict Handling with Assistive Guidance
When renames or ambiguous changes are detected, the CLI pauses and provides conflict resolution prompts. Developers write small mapping functions to resolve these manually—but only when needed.
Stored Functions Bridge Versions
When going from version 3 to 6, the system walks through and executes each required migration function in order. It never skips intermediate migrations unless explicitly marked as "collapsible."
Stored in Source Control
Snapshots and migrations live in your repo (e.g.,
wwwroot/__migrations__
) so they’re versioned with your code and deployed with your app.Automation with Blazor / C#
This system is language-agnostic at its core, but full automation is supported for Blazor and C# projects via a NuGet + CLI tool combo.
magic-indexdb snapshot
(or similar)Non-C# devs can still follow the same protocol manually—the format is documented, and the enforcement system still provides immense value. But C# devs get a fully automated path.
Resilience: Failure Is Not an Option
Client-side IndexedDB corruption is unacceptable—especially for offline-first, decentralized apps. This protocol is designed to self-heal:
Your data stays safe, and your app doesn’t break—period.
Acknowledging IndexedDB's Nature
IndexedDB is not a relational system. No joins. No foreign keys. No built-in constraints.
So instead of fighting that, we embrace it:
What It Looks Like (Simplified)
If you ran a snapshot:
Once resolved, the CLI generates a versioned function:
Already Prototyped in Production Environments
This isn’t theory. I’ve built and run versions of this system between both production at scale and via prototyping. The scaffolding CLI has been deployed by my company for national use for years. It's merely a small addition. The dynamic scaffolding and migration system has been prototyped manually already. The current proposal is a formalization and automation of what’s already worked.
Call for Feedback
This is a radical shift, I know. But I believe it’s the right way forward for anyone trying to build serious apps with IndexedDB. I’m opening this up to hear:
Let’s shape this together. The protocol, snapshot structure, CLI commands (which is actually both commands and a CLI GUI), and fallback options are still evolving—and I’d love to build this with the community’s input.
d I’d love to build this with the community’s input.
Thanks for reading!
Beta Was this translation helpful? Give feedback.
All reactions