Skip to content

feat(database)!: allow setting char size#2087

Open
regnerisch wants to merge 3 commits intotempestphp:3.xfrom
regnerisch:3.x
Open

feat(database)!: allow setting char size#2087
regnerisch wants to merge 3 commits intotempestphp:3.xfrom
regnerisch:3.x

Conversation

@regnerisch
Copy link
Copy Markdown

@regnerisch regnerisch commented Mar 29, 2026

Until now it was not possible to set a specific CHAR size inside the migration:

->char('uuid')

With this PR, users are now forced to set a CHAR size:

->char('uuid', 36)

As Postgres and MySQL consider the previous foo CHAR as foo CHAR(1), this seems to be a breaking change. So maybe changing private int $size = 1 would be better?

Postgres:

If character (or char) lacks a specifier, it is equivalent to character(1)
(https://www.postgresql.org/docs/current/datatype-character.html)

MySQL:

If M is omitted, the length is 1
(https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html)

Copy link
Copy Markdown
Member

@innocenzi innocenzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is definitely a breaking change, I think that's something we want here, be more explicit 👍

If you use CHAR, it's generally because you expect a specific length, so it doesn't make sense to have an implicit 1 as a default

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 29, 2026

Benchmark Results

Comparison of 3.x against 3.x (f1162475c1a432bec8d9c8442f46f7c895db7765).

Open to see the benchmark results

No benchmark changes above ±5%.

Generated by phpbench against commit 03ae720

@innocenzi innocenzi changed the title feat(database): allow setting char size feat(database)!: allow setting char size Mar 29, 2026
* Adds a `CHAR` column to the table.
*/
public function char(string $name, bool $nullable = false, ?string $default = null): self
public function char(string $name, int $size, bool $nullable = false, ?string $default = null): self
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's set the default to 1, that way it's not a breaking change and I think it makes sense for 1 to be default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants