Opt-in rules: require explicit names for indexes, unique constraints and foreign keys
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- php
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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!
- Ngôn ngữ chính
- PHP
- Star
- 683
- Fork
- 129
- Merge trung bình
- 13 giờ 6 phút
- Pull request đã merge (30 ngày)
- 14
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phpstan/phpstan-doctrine
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
phpstan/phpstan-doctrine#816 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
EntityRepository.stub missing Selectable interfaceCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
phpstan/phpstan-doctrine#785 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
phpstan/phpstan-doctrine#822 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ORM 3.7 SortDirection support in orderBy clauseCó thể đã có người làm @whataboutpereira đã nhận 48 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
phpstan/phpstan-doctrine#792 · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
phpstan/phpstan-doctrine#788 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của phpstan/phpstan-doctrine
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
phpstan/phpstan-phpunit#361 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
HE-Arc/le-panier-du-coin#49 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 2 ngày
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·