Existing database

Pull a live database, generate the first migration, then baseline without running DDL.

A live database with no OKModel history can be adopted without replaying DDL.

Terminal
bunx okm pull
bunx okm generate init
bunx okm migrate baseline

okm pull writes table files and the schema from the database. A policy is listed under not pulled yet, and so are enable row level security and force row level security on that table. okm check after baseline does not ask to drop that security when the schema declares no policy. An index keeps its database name: when that name is not {table}_{columns}_idx, the table file sets it with .name(), and a predicate or expression is set on that call. Baseline matches. Relative imports keep the .ts extension. When tsc typechecks that output, set allowImportingTsExtensions with noEmit, or set rewriteRelativeImportExtensions. okm generate init writes the head snapshot. okm migrate baseline records that snapshot as applied history: it writes okm_meta and okm_history only. It does not create, alter, or drop user objects.

Before it writes, baseline introspects the target. A difference on managed objects is OKM1858 and prints the plan that would reconcile them. Objects the model does not name are listed as unmanaged and are left alone. A target that already has OKModel history is OKM1857. A protected target needs --allow-protected.

After a successful baseline, okm generate prints no changes when the schema still matches, and okm migrate check passes. Later changes use generate and apply as usual.

Terminal
bunx okm migrate baseline --dry-run
bunx okm migrate baseline --json

--dry-run prints what would be recorded. --json puts the unmanaged list in envelope data. Running baseline again on the same mark prints already baselined and changes nothing.

baseline(target) from okmodel/migrate is the programmatic entry. default is the database target.