Skip to content

Commit

Permalink
migrations #364, #446, #287, #441, #265, #320
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jan 28, 2020
1 parent f6a6d54 commit b050c9a
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions src/migrations/m200128_141129_v3_update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

use yii\db\Migration;

/**
* Class m190521_145029_admin_user_notification
*/
class m200128_141129_v3_update extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
// user login agent
$this->addColumn('{{%admin_user_login}}', 'user_agent', $this->string());

// user device
$this->createTable('{{%admin_user_device}}', [
'id' => $this->primaryKey(),
'user_id' => $this->integer()->notNull(),
'auth_key' => $this->string(190)->unique()->notNull(),
'user_agent' => $this->string()->notNull(),
'user_agent_checksum' => $this->string()->notNull(),
'created_at' => $this->integer(),
'updated_at' => $this->integer(),
]);

$this->createIndex('user_id', '{{%admin_user_device}}', ['user_id']);
$this->createIndex('auth_key', '{{%admin_user_device}}', ['auth_key']);

// user 2fa
$this->addColumn('{{%admin_user}}', 'login_2fa_enabled', $this->boolean()->defaultValue(false));
$this->addColumn('{{%admin_user}}', 'login_2fa_secret', $this->string());
$this->addColumn('{{%admin_user}}', 'login_2fa_backup_key', $this->string());

// queue
$this->createTable('{{%admin_queue_log_error}}', [
'id' => $this->primaryKey(),
'queue_log_id' => $this->integer()->notNull(),
'message' => $this->text(),
'code' => $this->string(),
'trace' => $this->text(),
'file' => $this->text(),
'line' => $this->string(),
'created_at' => $this->integer(),
'updated_at' => $this->integer(),
]);

$this->createIndex('queue_log_id', '{{%admin_queue_log_error}}', 'queue_log_id');

// user login lockout
$this->createTable('{{%admin_user_login_lockout}}', [
'id' => $this->primaryKey(),
'user_id' => $this->integer()->notNull(),
'ip' => $this->string(45)->notNull(),
'attempt_count' => $this->integer()->defaultValue(0),
'created_at' => $this->integer(),
'updated_at' => $this->integer(),
]);

$this->createIndex('user_id', '{{%admin_user_login_lockout}}', 'user_id');

// password restore link
$this->addColumn('{{%admin_user}}', 'password_verification_token', $this->string(40));
$this->addColumn('{{%admin_user}}', 'password_verification_token_timestamp', $this->integer());
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
// user login UA
$this->dropColumn('{{%admin_user_login}}', 'user_agent');

// user device
$this->dropTable('{{%admin_user_device}}');

// user 2fa
$this->dropColumn('{{%admin_user}}', 'login_2fa_enabled');
$this->dropColumn('{{%admin_user}}', 'login_2fa_secret');
$this->dropColumn('{{%admin_user}}', 'login_2fa_backup_key');

// queue error log
$this->dropTable('{{%admin_queue_log_error}}');

// user lockout
$this->dropTable('{{%admin_user_login_lockout}}');

// password restore link
$this->dropColumn('{{%admin_user}}', 'password_verification_token');
$this->dropColumn('{{%admin_user}}', 'password_verification_token_timestamp');
}
}

0 comments on commit b050c9a

Please sign in to comment.