80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Database\Migrations;
|
||
|
|
|
||
|
|
use CodeIgniter\Database\Migration;
|
||
|
|
|
||
|
|
class CreateUsersTable extends Migration
|
||
|
|
{
|
||
|
|
public function up()
|
||
|
|
{
|
||
|
|
$this->forge->addField([
|
||
|
|
'id' => [
|
||
|
|
'type' => 'INT',
|
||
|
|
'constraint' => 11,
|
||
|
|
'unsigned' => true,
|
||
|
|
'auto_increment' => true,
|
||
|
|
],
|
||
|
|
'role_id' => [
|
||
|
|
'type' => 'INT',
|
||
|
|
'constraint' => 11,
|
||
|
|
'unsigned' => true,
|
||
|
|
],
|
||
|
|
'username' => [
|
||
|
|
'type' => 'VARCHAR',
|
||
|
|
'constraint' => 100,
|
||
|
|
],
|
||
|
|
'email' => [
|
||
|
|
'type' => 'VARCHAR',
|
||
|
|
'constraint' => 255,
|
||
|
|
],
|
||
|
|
'phone_number' => [
|
||
|
|
'type' => 'VARCHAR',
|
||
|
|
'constraint' => 20,
|
||
|
|
'null' => true,
|
||
|
|
],
|
||
|
|
'password_hash' => [
|
||
|
|
'type' => 'VARCHAR',
|
||
|
|
'constraint' => 255,
|
||
|
|
],
|
||
|
|
'telegram_id' => [
|
||
|
|
'type' => 'BIGINT',
|
||
|
|
'constraint' => 20,
|
||
|
|
'null' => true,
|
||
|
|
],
|
||
|
|
'is_active' => [
|
||
|
|
'type' => 'TINYINT',
|
||
|
|
'constraint' => 1,
|
||
|
|
'default' => 1,
|
||
|
|
],
|
||
|
|
'last_login_at' => [
|
||
|
|
'type' => 'DATETIME',
|
||
|
|
'null' => true,
|
||
|
|
],
|
||
|
|
'created_at' => [
|
||
|
|
'type' => 'DATETIME',
|
||
|
|
'null' => true,
|
||
|
|
],
|
||
|
|
'updated_at' => [
|
||
|
|
'type' => 'DATETIME',
|
||
|
|
'null' => true,
|
||
|
|
],
|
||
|
|
]);
|
||
|
|
|
||
|
|
$this->forge->addKey('id', true);
|
||
|
|
$this->forge->addUniqueKey('username');
|
||
|
|
$this->forge->addUniqueKey('email');
|
||
|
|
$this->forge->addUniqueKey('phone_number');
|
||
|
|
$this->forge->addUniqueKey('telegram_id');
|
||
|
|
$this->forge->addKey('role_id');
|
||
|
|
$this->forge->addForeignKey('role_id', 'roles', 'id', 'CASCADE', 'CASCADE');
|
||
|
|
$this->forge->createTable('users', true, ['ENGINE' => 'InnoDB']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function down()
|
||
|
|
{
|
||
|
|
$this->forge->dropTable('users');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|