Repository navigation
Render an unnamed Index as INDEX (col) instead of throwing - #269
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The Index constructor's name is optional, but getExpressionData() always wrapped the name in an Identifier, so an index built without a name, or with an empty one, threw "Identifier "" is empty" when a CREATE TABLE or ALTER TABLE was rendered. laminas-db rendered these as INDEX (col) and let the database generate the name. Drop the name placeholder from the specification when the name is empty. Column lengths and the USING type render as before, and named indexes are unchanged. Document the name as optional. Fixes php-db#265 Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
simon-mundy
force-pushed
the
fix/265-unnamed-index
branch
from
December 1, 2026 02:38
38ff3a4 to
249d63c
Compare
tyrsson
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #265
Problem
new Index('email')with no name fails when rendered, becauseIndex::getExpressionData()always wraps the name in anIdentifier, which rejects an empty string. laminas-db renderedINDEX (`email`), which MySQL accepts by generating the index name.Fix
nullor''),IndexrendersINDEX ("email"), leaving out the name and its placeholder. Lengths andUSINGtypes are kept.docs/book/sql-ddl/constraints.mdshows an unnamed index and notes that the name is optional.What stays the same
UniqueKey,PrimaryKey,ForeignKeyandCheckalready left outCONSTRAINTfor an empty name and are not touched.Tests
IndexTest: a data provider of seven unnamed variants (no name,null,'', with lengths, several columns) checks the expression data and the rendered SQL in bothCREATE TABLEandALTER TABLE ... ADD, with regression tests for named indexes.Indexhas 100% line and branch coverage.mago lintis clean andmago analyzereports nothing new.