Skip to content

[#86] - make:model: a schema for each table - #112

Merged
niden merged 7 commits into
masterfrom
T86-make-model-schema-per-table
Nov 28, 2026
Merged

niden merged 7 commits into
masterfrom
T86-make-model-schema-per-table

Conversation

@niden

@niden niden commented Nov 28, 2026

Copy link
Copy Markdown
Member

Hello!

In raising this pull request, I confirm the following:

  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • composer test, composer cs and composer analyze all pass
  • I have created a PR for the documentation about this change, if user facing

models.schema takes a list of schemas, for example ['public', 'billing']. The first is the default schema. A project with tables in more than one schema can use crest for all of them, and a foreign key between two schemas of the list gives a relation.

The rules:

  • A name with no schema is a table of the default schema. A table of another schema is <schema>.<table>: in make:model, make:scaffold, --exclude, the keys of models.classes and the RelationAlias keys. <default>.<table> is the table, also with a string key.
  • make:model --all writes a model for each table of each schema; each base calls setSchema() with the schema of its table, and its comment gives make:model <schema>.<table>.
  • A name with a schema that the list does not have stops before the boot. A table that the default schema does not have stops, with did you mean <schema>.<table>? when another schema of the list has it.
  • Two tables that give one class: the table of the default schema keeps it; the other table stops until models.classes gives it a class. This also stops a run for one table before it writes over the base of the other table.
  • With a list, crest gets the schema of a key from getReferencedSchema(): a key to a schema of the list gives a belongsTo() and a hasMany(); a key to another schema gives a Skipped line that names the schema. A string, or no key, reads the keys as before. Before cphalcon 5.24.0, PostgreSQL gives the database as the referenced schema (cphalcon #17816), so there a list gives a Skipped line for each key; phalcon/phalcon v6.0.x and cphalcon 5.24.0 have the fix.
  • config:show shows the list.

Changes in crest:

  • ModelNames: the list, schemas(), isList(), schemaOf() and tableOf() of a name, name(), nameOf(), withTables(), and the class check of a table of another schema.
  • ModelTables::listed() (the tables and views of each schema), ForeignKeys::read() with the ModelNames of the run, ModelRelations (the reason of a Skipped line, the alias of a key of many columns), ModelProperties::ofName().
  • The stub model-base: the comment uses {{ name }}; {{ table }} stays the table for setSource(). A published copy works.

Tests: unit, and ModelCommandSchemasTest on MySQL, MariaDB and PostgreSQL (two schemas end to end, with rows read across the schemas). With ext-phalcon before 5.24.0, the 3 PostgreSQL tests of keys between schemas skip (skipReferencedSchemaOnOldCphalcon()). Infection on the changed generator files: MSI 100%.

Thanks

…eys and the classes of each schema, and <schema>.<table> for a table that is not in the default schema

Assisted-by: Claude Code
…lass of a table of another schema, the keys between two schemas, and the servers

Assisted-by: Claude Code
Assisted-by: Claude Code
…ude and models.classes

Assisted-by: Claude Code
Assisted-by: Claude Code
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…ge run reaches the class check of one table

Assisted-by: Claude Code
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

Code Metrics Report

master (ede84a3) T86-make-model-schema-per-table (d9864c4) +/-
Coverage 99.8% 99.8% +0.0%
Test Execution Time 8s 9s +1s
Details
  |                     | master (ede84a3) | T86-make-model-schema-per-table |  +/-  |
  |                     |                  |            (d9864c4)            |       |
  |---------------------|------------------|---------------------------------|-------|
+ | Coverage            |            99.8% |                           99.8% | +0.0% |
  |   Files             |               97 |                              97 |     0 |
  |   Lines             |             4034 |                            4196 |  +162 |
+ |   Covered           |             4027 |                            4189 |  +162 |
- | Test Execution Time |               8s |                              9s |   +1s |

Code coverage of files in pull request scope (100.0% → 100.0%, patch 100.0%)

Files Coverage +/- Patch Coverage Status
src/Command/Config/ShowCommand.php 100.0% 0.0% 100.0% modified
src/Command/Make/MakeTypes.php 0.0% 0.0% - modified
src/Command/Make/ModelCommand.php 100.0% 0.0% 100.0% modified
src/Command/Make/ScaffoldCommand.php 100.0% 0.0% 100.0% modified
src/Generator/ForeignKeys.php 100.0% 0.0% 100.0% modified
src/Generator/ModelNames.php 100.0% 0.0% 100.0% modified
src/Generator/ModelProperties.php 100.0% 0.0% 100.0% modified
src/Generator/ModelRelations.php 100.0% 0.0% 100.0% modified
src/Generator/ModelTables.php 100.0% 0.0% 100.0% modified

Reported by octocov

@niden
niden merged commit 594a98b into master Nov 28, 2026
42 checks passed
@niden
niden deleted the T86-make-model-schema-per-table branch November 28, 2026 12:31
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