cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.45k stars 895 forks source link

Integers without signed declarations must be unsigned by default #2267

Open dereuromark opened 5 months ago

dereuromark commented 5 months ago

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.