module

Prostore::Diff::Engine

Pure function: (desired model definitions, prostore_schema rows) → ordered list of Operations.

Compares each model's Schema::Definition against the rows in prostore_schema (which is the library's record of the actual DB by tag). Per-tag identity (ADR-0002) drives rename detection; reservations (ADR-0008) drive drop detection. Type changes are detected here and surfaced via the validator (ADR-0003).

The engine does NOT consult live SQL DB metadata — that's the drift detector's job. It trusts prostore_schema to reflect the actual DB state, since the migration runner updates that table atomically with each successful step.

Instance methods

diff(models : Array(Prostore::Model.class), schema_rows : Array(Drift::SchemaTable::Row)) : Array(Operation::Any)

Top-level: diff every model in models against the schema-table rows; produce the full ordered operation list.

Tables in models whose name doesn't appear in schema_rows get CreateTable. Tables in schema_rows whose name doesn't appear in models are left alone — drop-table is the drift detector's responsibility; an unmanaged table is the operator's problem.

Source
diff_table(definition : Schema::Definition, rows : Array(Drift::SchemaTable::Row)) : Array(Operation::Any)

Per-table diff. Visible for unit testing.

Source
topological_sort(new_models : Array(Prostore::Model.class)) : Array(Prostore::Model.class)

Order new tables so a table is created after every table its foreign keys reference. Edges are restricted to the new-models set: FKs that reference an already-existing table need no ordering constraint.

Also used by Prostore.delete_all (reversed) to derive safe DELETE order.

Source