13 changed files with 497 additions and 0 deletions
@ -0,0 +1,45 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
|
||||
class Migration_create_ci_sessions_table extends Migration |
||||
{ |
||||
|
||||
public function up() |
||||
{ |
||||
$this->forge->addField([ |
||||
'id' => [ |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 128, |
||||
'null' => false |
||||
], |
||||
'ip_address' => [ |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 45, |
||||
'null' => false |
||||
], |
||||
'timestamp' => [ |
||||
'type' => 'INT', |
||||
'constraint' => 10, |
||||
'unsigned' => true, |
||||
'null' => false, |
||||
'default' => 0 |
||||
], |
||||
'data' => [ |
||||
'type' => 'TEXT', |
||||
'null' => false, |
||||
'default' => '' |
||||
], |
||||
]); |
||||
$this->forge->addKey('id', true); |
||||
$this->forge->addKey('timestamp'); |
||||
$this->forge->createTable('ci_sessions', true); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$this->forge->dropTable('ci_sessions', true); |
||||
} |
||||
} |
@ -0,0 +1,71 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_users_table extends Migration |
||||
{ |
||||
|
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
|
||||
$this->forge->addField([ |
||||
'id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
'auto_increment' => TRUE, |
||||
), |
||||
'email' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 254, |
||||
), |
||||
'username' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 150, |
||||
'null' => TRUE, |
||||
), |
||||
'password' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 60, |
||||
), |
||||
'banned' => array( |
||||
'type' => 'TINYINT', |
||||
'constraint' => 1, |
||||
'null' => TRUE, |
||||
'default' => 0, |
||||
), |
||||
'created_datetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', |
||||
'updated_datetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', |
||||
'last_activity' => array( |
||||
'type' => 'DATETIME', |
||||
'default' => NULL, |
||||
), |
||||
'last_ip_address' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 39, |
||||
'default' => '', |
||||
), |
||||
'last_login' => array( |
||||
'type' => 'DATETIME', |
||||
'default' => NULL, |
||||
), |
||||
'deleted' => array( |
||||
'type' => 'TINYINT', |
||||
'constraint' => 1, |
||||
'default' => 0, |
||||
), |
||||
]); |
||||
$this->forge->addKey('id', TRUE); |
||||
$this->forge->createTable($config->dbTableUsers, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTableUsers, true); |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_user_variables extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
'auto_increment' => TRUE, |
||||
), |
||||
'user_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
'data_key' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 100, |
||||
), |
||||
'data_value' => array( |
||||
'type' => 'TEXT', |
||||
), |
||||
'created_datetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', |
||||
'updated_datetime' => array( |
||||
'type' => 'DATETIME', |
||||
'default' => NULL, |
||||
), |
||||
'system' => array( |
||||
'type' => 'TINYINT', |
||||
'constraint' => 1, |
||||
'default' => 0, |
||||
), |
||||
]); |
||||
$this->forge->addKey('id', TRUE); |
||||
$this->forge->createTable($config->dbTableUserVariables, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTableUserVariables, true); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_login_attempts extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
'auto_increment' => TRUE, |
||||
), |
||||
'ip_address' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 39, |
||||
'default' => 0, |
||||
), |
||||
'count' => array( |
||||
'type' => 'TINYINT', |
||||
'constraint' => 2, |
||||
'default' => 0, |
||||
), |
||||
'created_datetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', |
||||
'updated_datetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', |
||||
]); |
||||
$this->forge->addKey('id', TRUE); |
||||
$this->forge->createTable($config->dbTableLoginAttempts, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTableLoginAttempts, true); |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_groups extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
'auto_increment' => TRUE, |
||||
), |
||||
'name' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 100, |
||||
), |
||||
'definition' => array( |
||||
'type' => 'TEXT', |
||||
), |
||||
]); |
||||
$this->forge->addKey('id', TRUE); |
||||
$this->forge->createTable($config->dbTableGroups, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTableGroups, true); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_group_to_user extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'group_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
'user_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
]); |
||||
$this->forge->addKey(array('group_id','user_id'), TRUE); |
||||
$this->forge->createTable($config->dbTableGroupToUser, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTableGroupToUser, true); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_group_to_group extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'group_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
'subgroup_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
]); |
||||
$this->forge->addKey(array('group_id','subgroup_id'), TRUE); |
||||
$this->forge->createTable($config->dbTableGroupToGroup, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTableGroupToGroup, true); |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_perms extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
'auto_increment' => TRUE, |
||||
), |
||||
'name' => array( |
||||
'type' => 'VARCHAR', |
||||
'constraint' => 100, |
||||
), |
||||
'definition' => array( |
||||
'type' => 'TEXT', |
||||
), |
||||
]); |
||||
$this->forge->addKey('id', TRUE); |
||||
$this->forge->createTable($config->dbTablePerms, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTablePerms, true); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_perm_to_user extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'perm_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
'user_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
]); |
||||
$this->forge->addKey(array('perm_id','user_id'), TRUE); |
||||
$this->forge->createTable($config->dbTablePermToUser, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTablePermToUser, true); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_perm_to_group extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->addField([ |
||||
'perm_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
'group_id' => array( |
||||
'type' => 'INT', |
||||
'constraint' => 11, |
||||
'unsigned' => TRUE, |
||||
), |
||||
]); |
||||
$this->forge->addKey(array('perm_id','user_id'), TRUE); |
||||
$this->forge->createTable($config->dbTablePermToGroup, TRUE); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
$this->forge->dropTable($config->dbTablePermToGroup, true); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_default_groups extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
|
||||
$data = [ |
||||
[ |
||||
'name' => $config->adminGroup, |
||||
'definition' => 'Administators', |
||||
], |
||||
[ |
||||
'name' => $config->defaultGroup, |
||||
'definition' => 'Users', |
||||
], |
||||
[ |
||||
'name' => $config->publicGroup, |
||||
'definition' => 'Guests', |
||||
], |
||||
]; |
||||
|
||||
$this->db->table($config->dbTableGroups)->insertBatch($data); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$this->db->table($config->dbTableGroups)->truncate(); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
<?php namespace Magefly\Aauth\Database\Migrations; |
||||
|
||||
use CodeIgniter\Database\Migration; |
||||
use Magefly\Aauth\Config\Aauth as AauthConfig; |
||||
|
||||
class Migration_create_default_admin extends Migration |
||||
{ |
||||
public function up() |
||||
{ |
||||
$config = new AauthConfig(); |
||||
|
||||
$data = [ |
||||
'username' => 'admin', |
||||
'email' => 'admin@example.com', |
||||
'password' => password_hash('password123456', $config->passwordHashAlgo, $config->passwordHashOptions), |
||||
]; |
||||
|
||||
$this->db->table($config->dbTableUsers)->insert($data); |
||||
|
||||
$data = [ |
||||
[ |
||||
'group_id' => 1, |
||||
'user_id' => 1, |
||||
], |
||||
[ |
||||
'group_id' => 2, |
||||
'user_id' => 1, |
||||
], |
||||
]; |
||||
|
||||
$this->db->table($config->dbTableGroupToUser)->insertBatch($data); |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function down() |
||||
{ |
||||
$this->db->table($config->dbTableUsers)->truncate(); |
||||
$this->db->table($config->dbTableGroupToUser)->truncate(); |
||||
} |
||||
} |
Loading…
Reference in new issue