@makaio/storage-migrations
Centralized Drizzle migration management: schema discovery, aggregation, and runtime migration application.
What This Is
Section titled “What This Is”Framework central runner for SQLite schema migrations. Provides:
- Schema discovery — Scans workspace
package.jsonfiles formakaio.drizzleSchemadeclarations and resolves them to absolute paths - Schema aggregation — Generates a combined
.generated/schema.tsthat Drizzle Kit uses to produce SQL migration files - Runtime migration application —
readMigrations()andapplyMigrations()apply pre-resolved SQL migrations at startup without Drizzle’smigrate()helper
Migration Tiers
Section titled “Migration Tiers”Makaio has two runtime migration tiers that share the same SQLite database but use separate ledgers:
- Central tier — Framework central migrations from this package use
__drizzle_migrations. Hosts may provide their own host-owned central migration bundle through an explicit composition seam; this framework package does not discover or apply host-owned schemas by filesystem convention. - Extension tier — Extension-owned schemas declare
storage.migrationson their package manifest. The runtime resolves those folders usingstorage.packageRootand keys each bundle withstorage.migrationSourceIdwhen provided, applying them to hashed tracking tables named__drizzle_migrations_<sha256>.
Key Exports
Section titled “Key Exports”getMigrationsFolder()— Absolute path to thedrizzle/migration folder (used byNodeRuntime)readMigrations(source?)— Reads_journal.jsonplus SQL files into ordered migration entriesapplyMigrations(db, migrations, migrationsTable?)— Applies ordered entries with a configurable tracking tablediscoverSchemas(workspaceRoot, patterns?)— ReturnsDiscoveredSchema[]sorted by package namegenerateSchema(options?)— Writes the aggregated.generated/schema.ts; accepts optionalworkspaceRoot,generatedDir,logger, andpatternsoverridesDiscoveredSchema—{ packageName: string; schemaPath: string }
Dev-time Workflow
Section titled “Dev-time Workflow”Framework central packages declare their Drizzle schema file in package.json:
{ "name": "@makaio/my-framework-package", "makaio": { "drizzleSchema": [ "./src/storage/schema.ts" ] }}Extension-owned schemas should not use makaio.drizzleSchema; declare storage.migrations
with storage.packageRoot and, for bundled hosts, storage.migrationSourceId on the extension
manifest instead.
Then run the standalone framework workspace commands from the framework repo root:
yarn workspace @makaio/storage-migrations db:generateyarn workspace @makaio/storage-migrations db:generate:freshyarn workspace @makaio/storage-migrations db:pushyarn workspace @makaio/storage-migrations db:studioyarn workspace @makaio/storage-migrations db:resetRuntime Usage
Section titled “Runtime Usage”initializeNodeDatabase() creates the database client and calls runMigrations():
import { applyMigrations, readMigrations } from '@makaio/storage-migrations';
const migrations = readMigrations();await applyMigrations(db, migrations);The startup path is initializeNodeDatabase() → runMigrations() → readMigrations() /
applyMigrations(). It does not call Drizzle’s migrate().
During node boot, framework central migrations run after bus and transport creation, but before
the database handle is published on RuntimeSubjects.database, before storage handlers are
registered, and before extension storage or services start. Extension migrations declared through
storage.migrations run later inside ExtensionCoordinator.startAll(), still before each
extension’s storage handlers and services start.
Architecture
Section titled “Architecture”@makaio/storage-migrations owns the framework central migration runner. Framework packages
declare central schemas locally via makaio.drizzleSchema; host-owned central schemas belong in a
separate host-owned migration bundle wired by the host composition root; extension-owned tables use
storage.migrations instead of joining either central bundle.
The discovery step (discoverSchemas) reads workspaces from the provided workspace root
package.json to enumerate packages, making it resilient to workspace structure changes without
manual updates.
Part of Makaio Framework