85 lines
3.0 KiB
PHP
85 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class SuperUser extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
$db = \Config\Database::connect();
|
|
if ($db->getPrefix() && ($db->getPlatform() == 'Postgre')) {
|
|
$pr = $db->getPrefix();
|
|
$ff = explode('.', $pr);
|
|
$db->query('ALTER TABLE ' . $ff[1] . '.super_user ADD CONSTRAINT super_user_pk PRIMARY KEY (super_user_id)');
|
|
$db = new \Config\Database;
|
|
$dbSelect = $db->default;
|
|
$dbSelect['DBPrefix'] = '';
|
|
$dbSelect['schema'] = 'Postgre';
|
|
$forge = \Config\Database::forge($dbSelect);
|
|
$forge->addField([
|
|
'super_user_id' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
],
|
|
'super_user_unique' => [
|
|
'type' => 'INT',
|
|
'constraint' => 255,
|
|
'auto_increment' => true,
|
|
'unique' => true,
|
|
],
|
|
'super_group_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 5,
|
|
],
|
|
'domain_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 5,
|
|
],
|
|
'name' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
],
|
|
'email' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
'null' => true,
|
|
],
|
|
'username' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
],
|
|
'password' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
],
|
|
'avatar' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
'null' => true,
|
|
],
|
|
'status' => [
|
|
'type' => 'INT',
|
|
'constraint' => 1,
|
|
'null' => true,
|
|
],
|
|
'token' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 200,
|
|
'null' => true,
|
|
],
|
|
'created_at timestamp without time zone NULL DEFAULT CURRENT_TIMESTAMP',
|
|
'login_date timestamp without time zone NULL DEFAULT CURRENT_TIMESTAMP',
|
|
'access_at timestamp without time zone NULL DEFAULT CURRENT_TIMESTAMP'
|
|
]);
|
|
$forge->createTable($ff[1] . '.super_user');
|
|
$db = \Config\Database::connect();
|
|
}
|
|
}
|
|
public function down()
|
|
{
|
|
$this->forge->dropTable('super_user');
|
|
}
|
|
}
|