Opt-in rules: require explicit names for indexes, unique constraints and foreign keys
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- php
- Ambito
- testing-qa
Direzione di ricerca
Start by reading the existing reportDynamicQueryBuilders parameter and how rules load ClassMetadata; the issue names table.indexes, table.uniqueConstraints, and association join columns as the metadata to inspect. Check which ORM versions expose JoinColumnMapping::foreignKeyName, then add tests for the opt-in parameter and its version-dependent behavior. Done means the rules detect mapping-generated names when enabled and remain off by default.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Would you accept opt-in rules that report indexes, unique constraints and foreign keys left without an explicit name? I'd like to ask before writing a PR.
The problem
When a mapping gives no name, DBAL generates one from a prefix and a crc32 hash of the table name and column names (AbstractAsset::_generateIdentifierName(), called from Table with [$tableName, ...$columnNames]). That causes two problems:
- Migration churn. Renaming a table or a column changes the generated name, so the next diff drops the index or constraint and creates it again. On a large table that is an expensive rebuild, and for a unique constraint or foreign key it leaves a window where the constraint does not exist.
- Opaque errors. A violation reads
violates foreign key constraint "FK_8D93D649A76ED395", which tells whoever is on call nothing about which relation failed.
Both are avoidable, since every one of these names can be set in the mapping: name on #[Index] and #[UniqueConstraint], and foreignKeyName on #[JoinColumn]. Nothing reports a missing one today.
Proposal
Rules that read ClassMetadata through the existing object manager loader, so they work with every mapping driver and not only attributes:
- Every entry in
table.indexesandtable.uniqueConstraintshas a name that was declared in the mapping, not generated. - The join columns of every owning
ManyToOne,OneToOneandManyToManyassociation declare a foreign key name. This one only applies on ORM versions whereJoinColumnMappinghasforeignKeyName, and would do nothing on older ones.
Both would be off by default behind one parameter, the way reportDynamicQueryBuilders is, so nobody gets new errors without asking for them.
Prior work
I maintain a working attribute-based version of these rules in a private codebase. I'd port it onto ClassMetadata for this extension, with tests.
If this is out of scope here, that's fine. I'll publish them as a standalone extension instead. Thanks!
- Lingua principale
- PHP
- Stelle
- 683
- Fork
- 129
- Merge medio
- 13h 6m
- PR unite (30g)
- 14
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di phpstan/phpstan-doctrine
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
phpstan/phpstan-doctrine#816 ·
I maintainer di solito rispondono entro 1 giorno
-
EntityRepository.stub missing Selectable interfaceForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
phpstan/phpstan-doctrine#785 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
phpstan/phpstan-doctrine#822 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ORM 3.7 SortDirection support in orderBy clauseForse già presa @whataboutpereira l’ha presa 48 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
phpstan/phpstan-doctrine#792 · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
phpstan/phpstan-doctrine#788 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di phpstan/phpstan-doctrine
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
phpstan/phpstan-phpunit#361 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
HE-Arc/le-panier-du-coin#49 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 2 giorni
-
15.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·