53 lines
1.8 KiB
PHP
Executable File
53 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
use common\components\Migration\MigrationWithDefaultOptions;
|
|
use common\models\User;
|
|
|
|
class m140703_123000_user extends MigrationWithDefaultOptions
|
|
{
|
|
public function up()
|
|
{
|
|
$tableOptions = null;
|
|
if ($this->db->driverName === 'mysql') {
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
|
|
}
|
|
|
|
$this->createTable('{{%user}}', [
|
|
'id' => $this->primaryKey(),
|
|
'username' => $this->string(32),
|
|
'auth_key' => $this->string(32)->notNull(),
|
|
'password_hash' => $this->string()->notNull(),
|
|
'password_reset_token' => $this->string(),
|
|
'oauth_client' => $this->string(),
|
|
'oauth_client_user_id' => $this->string(),
|
|
'email' => $this->string()->notNull(),
|
|
'status' => $this->smallInteger()->notNull()->defaultValue(User::STATUS_ACTIVE),
|
|
'created_at' => $this->integer(),
|
|
'updated_at' => $this->integer(),
|
|
'logged_at' => $this->integer()
|
|
], $tableOptions);
|
|
|
|
$this->createTable('{{%user_profile}}', [
|
|
'user_id' => $this->primaryKey(),
|
|
'firstname' => $this->string(),
|
|
'middlename' => $this->string(),
|
|
'lastname' => $this->string(),
|
|
'avatar_path' => $this->string(),
|
|
'avatar_base_url' => $this->string(),
|
|
'locale' => $this->string(32)->notNull(),
|
|
'gender' => $this->smallInteger(1)
|
|
], $tableOptions);
|
|
|
|
$this->addForeignKey('fk_user', '{{%user_profile}}', 'user_id', '{{%user}}', 'id', 'cascade', 'cascade');
|
|
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
$this->dropForeignKey('fk_user', '{{%user_profile}}');
|
|
$this->dropTable('{{%user_profile}}');
|
|
$this->dropTable('{{%user}}');
|
|
|
|
}
|
|
}
|