yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Migrations - support for non integer primary keys #12767

Closed tsanchev closed 8 years ago

tsanchev commented 8 years ago

This is not an issue but a suggestion

It would be great if non integer primary keys can be created in this way

$this->createTable('messages', [
    'message_id' => $this->string()->primaryKey(), // or maybe $this->primaryKey()->string()
]);

Instead of this:

$this->createTable('messages', [
    'message_id' => $this->string()->notNull(),
    'PRIMARY KEY (message_id)',
]);

In general my recommendation for primary keys is if there is a type specification, the primary key is of the specified type. Thus eliminating the need of bigPrimaryKye which can be declared using $this->bigInteger()->primaryKey(). If the type is not specified the primary key defaults to integer as is now.

There is already core code in Yii2 which can take advantage of this - rbac migrations

This support should also be implemented and in "migration generation" for example

yii migrate/create create_messages_table --fields="message_id:string:primaryKey"
rob006 commented 8 years ago

Duplicates https://github.com/yiisoft/yii2/issues/11638