Skip to content

Use consistent formatting in PRIMARY KEY DDL#6864

Merged
morozov merged 1 commit intodoctrine:4.3.xfrom
morozov:primary-key-ddl-formatting
Mar 21, 2025
Merged

Use consistent formatting in PRIMARY KEY DDL#6864
morozov merged 1 commit intodoctrine:4.3.xfrom
morozov:primary-key-ddl-formatting

Conversation

@morozov
Copy link
Copy Markdown
Member

@morozov morozov commented Mar 20, 2025

Currently, the PRIMARY KEY (...) DDL is inconsistently formatted across the codebase. The open parenthesis is sometimes padded with space:

return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . implode(', ', $index->getQuotedColumns($this)) . ')';
...and sometimes is not:
$columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')';

When it comes to refactoring this code and reusing one implementation in another, some unit tests start failing because of the changes in formatting.

Let's consistently use padding. This is consistent with the CREATE TABLE <name> (...), FOREIGN KEY (...) and CHECK (...) formatting:

$query = 'CREATE TABLE ' . $name . ' (' . $columnListSql;
$sql .= 'FOREIGN KEY (';
$constraints[] = 'CHECK (' . $def . ')';

@morozov morozov added this to the 4.3.0 milestone Mar 20, 2025
@morozov morozov marked this pull request as ready for review March 20, 2025 17:34
@morozov morozov requested a review from greg0ire March 20, 2025 17:34
@morozov morozov merged commit bbf0e04 into doctrine:4.3.x Mar 21, 2025
68 checks passed
@morozov morozov deleted the primary-key-ddl-formatting branch March 21, 2025 01:24
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants