[RFC]: DDL column classes for ENUM, SET and the remaining MySQL column types
維護者通常 2 天內回覆
@simon-mundy 已經在處理了。
開始於 2026年9月4日。
評估
這個 Issue 還沒有評估資料。
描述
Proposed Version
0.6.0
Basic Information
Currently Sql\Ddl\Column has 22 classes (the Laminas set plus Double, Json and SmallInteger from #138) and no way to express anything else. Column::$type is protected with no setter and no constructor argument (Column.php#L31, #L33-L38), so the only way to get an ENUM, SET, TINYINT, MEDIUMINT, BIT, YEAR, sized TEXT/BLOB or spatial column is to subclass. This proposal adds those classes, with ENUM/SET values emitted as Argument\Value so nothing caller-supplied reaches SQL as a literal, and fixes Text/Blob silently dropping their length.
Background
The read side is already ahead of the write side. PhpDb\Mysql\Metadata\Source parses enum(...)/set(...) into erratas['permitted_values'] (Source.php#L92-L103) and the enum path is integration-tested against the test_enum fixture (there is no SET fixture in mysql.sql). Nothing consumes permitted_values, and nothing can turn it back into DDL.
Text and Blob override $specification to %s %s (Text.php#L9-L11, Blob.php#L9-L12), so new Text('t', 100) renders TEXT and MySQL's TEXT(n) size selection is unreachable.
The phpdb-mysql-ddl-overrides branch on simon-mundy/phpdb-mysql already has Enum, Set, TinyInteger, MediumInteger, Bit, Year, the sized Text/Blob variants and all eight spatial types — in the adapter namespace PhpDb\Mysql\Sql\Ddl. It is 69 commits behind 0.5.x, pinned to a core branch that no longer exists, and predates the literal-slot rule (Enum quotes values with "'" . $v . "'" and no escaping). Useful for the design and the tests; not something to rebase.
Considerations
- Core or adapter — that is the real question. Core already hosts
Jsonand the MySQL-flavouredON UPDATE CURRENT_TIMESTAMPinAbstractTimestampColumn, so I have assumed core here with the adapter rendering onlySRID. The fork branch went the other way. - The sized Text/Blob variants must suppress the length entirely: MySQL rejects
TINYTEXT(100),MEDIUMBLOB(100)andLONGTEXT(10)with 1064. Column::setOption()is typedbool|string, so until it is widened (#169, also raised in phpdb-mysql#81) an int SRID goes through the constructor$optionsarray or as a string.- Clean rendering depends on the
AbstractLengthColumnValueError fix and theIntegerlength-position fix (#176 and #178). - Every rendering below (
YEAR NOT NULL,BIT(1),ENUM('a', 'b'),POINT SRID 4326) has been executed on MySQL 8.4.10 (reproduced on 8.0.46). - MariaDB and decorator work beyond
SRIDare out of scope.
Proposal(s)
In this order:
EnumandSet. Constructor(string $name, array $values, bool $nullable = false, string|int|float|bool|Literal|Value|null $default = null, array $options = []). Spec%s %s(%s, %s, ...)with oneArgument\Valueper member, so every value is quoted by the platform. Empty$valuesthrowsInvalidArgumentException.TinyInteger(TINYINT) andMediumInteger(MEDIUMINT) extendingInteger, same asSmallInteger.Bit(BIT(M)) extendingAbstractLengthColumn;Year(YEAR, no width —YEAR(4)is deprecated from 8.0.19).TinyText,MediumText,LongTextextendingText;TinyBlob,MediumBlob,LongBlobextendingBlob.Text/Blobthemselves either honour the length (TEXT(n),BLOB(n)) or reject it — the silent drop goes. The sized variants never emit a length.- Spatial:
Geometry,Point,LineString,Polygon,MultiPoint,MultiLineString,MultiPolygon,GeometryCollection, with ansridoption.SRID nis MySQL syntax (8.0.3+), so rendering it belongs in the MySQL decorator; core only carries the option.
Test plan:
new Enum('status', ['active', 'inactive'])renders`status` ENUM('active', 'inactive') NOT NULLon the MySQL platform with each value going throughquoteValue();SetrendersSET(...)the same way.- Every new class gets a unit test in
test/unit/Sql/Ddl/Column/asserting the rendered SQL string, not justgetExpressionData()containment. Text/Bloblength handling is explicit and tested; the sized variants never emit a length.- Round trip: the
test_enumfixture read through the metadataSource(coreAbstractSource::getColumn(), values viaColumnObject::getErrata('permitted_values')) can be re-expressed as anEnumwith the same values — integration test in phpdb-mysql. Add atest_setfixture and do the same forSet. - No new class emits a caller-supplied string as an
Argument\Literal.
Appendix/Additional Info
- #92 (parent), #91 (backed enums), #138 (previous DDL additions).
- From an internal DDL audit (not published — the findings are reproduced above).
- 主要語言
- PHP
- 星號
- 18
- 分支
- 8
- 平均合併
- 2 天 6 小時
- 30 天內合併 PR
- 30
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
php-db/phpdb 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 2 天內回覆
-
RFC
難度 3/5 1-2 天 新手友好度 66/100
維護者通常 2 天內回覆
-
RFC
難度 5/5 一週以上 新手友好度 38/100
維護者通常 2 天內回覆
-
RFC
難度 3/5 1-2 天 新手友好度 68/100
維護者通常 2 天內回覆
-
RFC
難度 4/5 3-5 天 新手友好度 45/100
維護者通常 2 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
Automattic/blocks-engine#3369 ·
維護者通常 1 天內回覆
-
0. to triage
難度 1/5 1 小時以內 新手友好度 67/100
roundcube/roundcubemail-docker#478 ·
維護者通常 1 天內回覆
-
0. Needs triage 35-feedback bug
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
product / auth product / databases product / functions product / messaging product / storage product / vcs
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
good first issue ux
難度 1/5 1 小時以內 新手友好度 89/100
alleyinteractive/wp-curate#498 ·
維護者通常 2 天內回覆