Integers without signed declarations must be unsigned by default
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 4.5k
- Forks
- 884
- PR merge metrics
- No merged PRs in 30d
Description
This is an inconsistency that triggers multiple issues along the road
Right now, not defining table primary key gets it added as "int unsigned".
But any integer added would be "signed", especially problematic for foreign keys, since those together with indexes (unique!) will cause DB errors.
So I propose that signed is false by default when the primary key is generated unsigned by default to match this
Example:
$this->table('comments')
->addColumn('user_id', 'integer', [
'default' => null,
'null' => true,
//'signed' => false, Should not be needed anymore unless someone needs a signed field here
])
should be
`id` int UNSIGNED NOT NULL,
`user_id` int UNSIGNED DEFAULT NULL,
When baking snapshots this also usually causes the
public bool $autoId = false;
and each primary key manually being added extra into the table definitions.
Also quite cumbersome and not DRY
This would probably also be resolved with it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the code that assigns default signedness to integer columns and the logic that generates unsigned primary keys. Compare generated primary-key and foreign-key definitions, then inspect any snapshot or migration tests covering integer columns. Done means omitted signed declarations produce unsigned integers consistently without requiring manual primary-key settings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100