Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with new migration 2.0.6 #6

Open
spiritdead opened this issue Aug 29, 2015 · 9 comments
Open

problem with new migration 2.0.6 #6

spiritdead opened this issue Aug 29, 2015 · 9 comments

Comments

@spiritdead
Copy link

hi all im trying this

'id' => Schema::TYPE_STRING . '(64) PRIMARY KEY',

but in the new migration i cant make this
'id' => $this->string(64)->primaryKey();

is a bug or this not exist in this case i cant define string to primary key ?

my suggestion is modify the primary key for support int and strings

$this->string()->primaryKey()->autoincrement(false);

or

$this->string->primaryKey($autoincrement = false);

i need this for the table sessions in this case

$this->createTable('session',[
            'id' => Schema::TYPE_STRING . '(64) PRIMARY KEY',
            'user_id' => Schema::TYPE_INTEGER,
            'ip' => Schema::TYPE_STRING,
            'is_trusted' => Schema::TYPE_BOOLEAN,
            'expire' => Schema::TYPE_INTEGER,
            'data' => Schema::TYPE_STRING,
            'controllerCurrent' => Schema::TYPE_STRING,
            'actionCurrent' => Schema::TYPE_STRING,
            'pageCurrent' => Schema::TYPE_STRING,
            'is_guest' => Schema::TYPE_BOOLEAN,
        ],$tableOptions);

in this case i don't need autoincrement,etc and the string is primary key

@cebe
Copy link
Member

cebe commented Aug 29, 2015

primaryKey() method is a predefined format of a primary key in form of an auto incremental integer. if you need another form of primarykey you currently can not use the columnschemabuilder for it.

@spiritdead
Copy link
Author

@cebe of course for this i make this issue for make a enhacement for the version 2.0.7
-support primary key for string and integer (for now is integer only)
-add a option for the autoincrement

@samdark
Copy link
Member

samdark commented Aug 29, 2015

I don't think it's possible w/o breaking compatibility.

@spiritdead
Copy link
Author

@samdark i know , but this limite the creator table, not all table work using integer and primary key
the best sample is the DB sessions (DBSession yii2)

@spiritdead
Copy link
Author

my suggestion is in the primary key define the type data, and if is autoincrement adding parameters
$this->primaryKey(integer = true, autoincrement = true) or adding consts IS_INTEGER, IS_STRING etc

@rugabarbo
Copy link
Member

@spiritdead, I think that your case isn't reason for enhancement. There are can be many other unique migration cases. Core team can't cover all custom cases.

Don't use columnschemabuilder for your case. Use custom definition for your PK column. Is it problem for you?

@spiritdead
Copy link
Author

@rugabarbo the standard PK is integer and string, i don't say other type of data, and the autoincrement is adding a parameter in the function primaryKey(), or you will limite this only autoincrement ?

and i show the default sample creating a migration for the table Sessions (this table is default in the core yii2 and this use String PK)

@mdmunir
Copy link

mdmunir commented Aug 31, 2015

👍
IMO, its OK to add method primaryKey() to yii\db\ColumnSchemaBuilder. Current primaryKey() method are belong to yii\db\Migration.

'id' => $this->primaryKey(), // --> 'id' => Schema::TYPE_PK

'user_id' => $this->integer()->primaryKey(), // --> 'user_id' => Schema::TYPE_INTEGER . ' PRIMARY KEY'

PS: To avoid confusion we can rename yii\db\Migration::primaryKey() to yii\db\Migration::serial(), yii\db\Migration::squence() or something like that.

@samdark samdark transferred this issue from yiisoft/yii2 Apr 23, 2019
@samdark samdark transferred this issue from yiisoft/db Apr 24, 2019
@Tigrov
Copy link
Member

Tigrov commented Oct 16, 2023

The issue related with yiisoft/db, primaryKey is a part of Yiisoft\Db\Schema\Builder\AbstractColumn class.

https://github.com/yiisoft/db/blob/4f1dbb95c9551b4359cdb2b188d0094bd70aa138/src/Schema/SchemaInterface.php#L124

https://github.com/yiisoft/db-mysql/blob/d48ca3a6ad83abf6ed97e146185c76c5ce2e55ab/src/QueryBuilder.php#L20

And this should be solved there

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

No branches or pull requests

6 participants