Skip to content

Instantly share code, notes, and snippets.

@calcio
Created March 24, 2017 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calcio/a792146f1b74c617ea4af0033d8f0cca to your computer and use it in GitHub Desktop.
Save calcio/a792146f1b74c617ea4af0033d8f0cca to your computer and use it in GitHub Desktop.
Migrate example - serie Vitrine project
<?php
use yii\db\Migration;
class m170104_184151_users extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('users', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull()->unique(),
'authKey' => $this->string(32)->notNull(),
'passwordHash' => $this->string()->notNull(),
'passwordResetToken' => $this->string()->unique(),
'email' => $this->string()->notNull()->unique(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->insert('users', [
'username' => 'admin',
'authKey' => Yii::$app->security->generateRandomString(),
'passwordHash' => Yii::$app->getSecurity()->generatePasswordHash('admin'),
'email' => 'admin@mail.com',
'status' => '10',
]);
}
public function down()
{
$this->dropTable('users');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment