Skip to content

feat(translate): emulate information_schema FK reflection views (CakePHP 5) - #61

Merged
luthermonson merged 1 commit into
mainfrom
fix/infoschema-fk-views
Oct 29, 2026
Merged

luthermonson merged 1 commit into
mainfrom
fix/infoschema-fk-views

Conversation

@luthermonson

Copy link
Copy Markdown
Contributor

CakePHP 5's schema reflection (describeForeignKeySql / describeCheckConstraints) queries information_schema.key_column_usage, referential_constraints, table_constraints and check_constraints. litewire didn't emulate them, so every table describe returned 1064 and the app 500'd.

What this adds

Four more emulated information_schema views, in the same derived-table style as the existing tables/columns/statistics/schemata emulation:

  • key_column_usage — one row per foreign-key column, all 12 MySQL columns. Derived from pragma_foreign_key_list; primary/unique columns are not listed. An implicit REFERENCES t resolves to the parent's key column.
  • referential_constraints — one row per FK, all 11 MySQL columns (incl. UPDATE_RULE/DELETE_RULE).
  • table_constraints — primary keys and foreign keys (UNIQUE/CHECK not listed).
  • check_constraints — always empty; SQLite keeps CHECK clauses only inside the CREATE text.

Unnamed SQLite FKs are named <table>_ibfk_<n>, matching MySQL's unnamed-InnoDB-key convention. constraint_schema and referenced_table_schema now fold like table_schema, so a bound schema name matches litewire's main.

Integer columns are CAST(... AS INTEGER): on Turso a prepared select of an integer expression through a derived table drops the connection unless the expression carries a declared type.

Tests

New mysql_infoschema_fk runs both CakePHP queries verbatim as prepared statements over the wire on rusqlite and Turso, plus plain SELECT * column-name checks, the empty case, FK rules (CASCADE/SET NULL), composite FKs, and table_constraints. clippy --all-targets -D warnings and nightly fmt are clean. (single_tenant_attach_keeps_working_over_the_wire fails identically on untouched main — a pre-existing Windows path issue.)

Verified end-to-end against the consolidated wun image: CakePHP's describe no longer 1064s and GET /api/products is byte-identical to the oracle.

Emulate information_schema.key_column_usage, referential_constraints,
table_constraints (primary + foreign keys) and check_constraints (always
empty). Foreign keys are derived from pragma_foreign_key_list and named
<table>_ibfk_<n>, matching MySQL's unnamed-InnoDB-key convention. Fold
constraint_schema and referenced_table_schema comparisons like table_schema
so a bound schema name matches litewire's main schema.

CakePHP 5 reads these views when it describes a table (describeForeignKeySql,
describeCheckConstraints) and failed with 1064 before.
@luthermonson
luthermonson merged commit ef896fb into main Oct 29, 2026
5 checks passed
@luthermonson
luthermonson deleted the fix/infoschema-fk-views branch October 29, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant