Path Finding
Automatic path discovery between schemas using BFS and Dijkstra.
Path Finding
When no direct migration exists between two schemas, doba automatically finds the optimal path through the migration graph.
How it works
Given these migrations:
const registry = createRegistry({
schemas: { legacy, database, frontend, ai },
migrations: {
'legacy->database': (data) => {
/* upgrade */
},
'database->frontend': (data) => {
/* strip sensitive */
},
'frontend->ai': (data) => {
/* flatten */
},
},
})Transforming from legacy to ai automatically chains through every intermediate schema:
const result = await registry.transform(legacyData, 'legacy', 'ai')
if (result.ok) {
console.log(result.meta.path)
// ["legacy", "database", "frontend", "ai"]
}Algorithm selection
doba automatically picks the right algorithm based on your migrations:
- BFS: all migrations have equal cost (no
cost,preferred, ordeprecatedoptions). Finds the shortest path by hop count. - Dijkstra: any migration has a custom cost, is marked
preferred(cost 0), ordeprecated(cost 1000). Finds the lowest-cost path.
You don't need to choose. The registry detects whether weighted edges exist at construction time.
Path strategies
shortest (default)
Finds the optimal path using BFS or Dijkstra. Handles graphs with 10k+ edges efficiently.
createRegistry({
pathStrategy: 'shortest',
// ...
})direct
Only uses direct migrations. Returns an error if no direct source->target migration exists.
createRegistry({
pathStrategy: 'direct',
// ...
})You can also override the strategy per-transform:
await registry.transform(data, 'a', 'b', {
pathStrategy: 'direct',
})Explicit paths
Override automatic path finding by specifying the exact route:
await registry.transform(data, 'a', 'd', {
path: ['a', 'b', 'c', 'd'],
})Inspecting paths
Use findPath to preview what route doba would take without running a transform:
const path = registry.findPath('legacy', 'ai')
// ["legacy", "database", "frontend", "ai"] or nullReturns null if no path exists between the two schemas.
Cost system
Migration costs control which paths the Dijkstra algorithm prefers:
| Option | Cost | Effect |
|---|---|---|
| (default) | 1 | Standard edge weight |
preferred: true | 0 | Always chosen over alternatives |
deprecated: true | 1000 | Avoided unless no other path exists |
cost: N | N | Explicit weight (overrides above) |
See Weighted Migrations for a full example.
Path finding runs in O(V + E) time (BFS) or O((V + E) log V) time (Dijkstra) where V is the number of schemas and E is the number of migrations.