From 26368e2c80d0a82d05fe8ff5e699dda0232b65e1 Mon Sep 17 00:00:00 2001 From: REJack Date: Mon, 11 Feb 2019 12:51:21 +0100 Subject: [PATCH] readded migrations --- ...81026042034_create_user_sessions_table.php | 82 ++++++++++++++ .../20181026110732_create_users_table.php | 104 ++++++++++++++++++ .../20181031062503_create_user_variables.php | 83 ++++++++++++++ .../20181031063113_create_login_attempts.php | 79 +++++++++++++ .../20181031063642_create_login_tokens.php | 80 ++++++++++++++ .../20181031064211_create_groups.php | 78 +++++++++++++ .../20181031064311_create_group_variables.php | 83 ++++++++++++++ .../20181031064431_create_group_to_user.php | 68 ++++++++++++ .../20181031064550_create_group_to_group.php | 68 ++++++++++++ .../20181031064714_create_perms.php | 78 +++++++++++++ .../20181031065111_create_perm_to_user.php | 73 ++++++++++++ .../20181031065240_create_perm_to_group.php | 73 ++++++++++++ .../20181031072542_create_default_groups.php | 70 ++++++++++++ .../20181031072914_create_default_users.php | 86 +++++++++++++++ 14 files changed, 1105 insertions(+) create mode 100644 app/Database/Migrations/20181026042034_create_user_sessions_table.php create mode 100644 app/Database/Migrations/20181026110732_create_users_table.php create mode 100644 app/Database/Migrations/20181031062503_create_user_variables.php create mode 100644 app/Database/Migrations/20181031063113_create_login_attempts.php create mode 100644 app/Database/Migrations/20181031063642_create_login_tokens.php create mode 100644 app/Database/Migrations/20181031064211_create_groups.php create mode 100644 app/Database/Migrations/20181031064311_create_group_variables.php create mode 100644 app/Database/Migrations/20181031064431_create_group_to_user.php create mode 100644 app/Database/Migrations/20181031064550_create_group_to_group.php create mode 100644 app/Database/Migrations/20181031064714_create_perms.php create mode 100644 app/Database/Migrations/20181031065111_create_perm_to_user.php create mode 100644 app/Database/Migrations/20181031065240_create_perm_to_group.php create mode 100644 app/Database/Migrations/20181031072542_create_default_groups.php create mode 100644 app/Database/Migrations/20181031072914_create_default_users.php diff --git a/app/Database/Migrations/20181026042034_create_user_sessions_table.php b/app/Database/Migrations/20181026042034_create_user_sessions_table.php new file mode 100644 index 0000000..feecf31 --- /dev/null +++ b/app/Database/Migrations/20181026042034_create_user_sessions_table.php @@ -0,0 +1,82 @@ +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($config->dbTableUserSessions, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableUserSessions, true); + } +} diff --git a/app/Database/Migrations/20181026110732_create_users_table.php b/app/Database/Migrations/20181026110732_create_users_table.php new file mode 100644 index 0000000..2cd9126 --- /dev/null +++ b/app/Database/Migrations/20181026110732_create_users_table.php @@ -0,0 +1,104 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'email' => [ + 'type' => 'VARCHAR', + 'constraint' => 254, + ], + 'username' => [ + 'type' => 'VARCHAR', + 'constraint' => 150, + 'null' => true, + ], + 'password' => [ + 'type' => 'VARCHAR', + 'constraint' => 255, + ], + 'banned' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'null' => true, + 'default' => 0, + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'last_activity' => [ + 'type' => 'DATETIME', + 'default' => null, + ], + 'last_ip_address' => [ + 'type' => 'VARCHAR', + 'constraint' => 39, + 'default' => '', + ], + 'last_login' => [ + 'type' => 'DATETIME', + 'default' => null, + ], + 'deleted' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 0, + ], + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTableUsers, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableUsers, true); + } +} diff --git a/app/Database/Migrations/20181031062503_create_user_variables.php b/app/Database/Migrations/20181031062503_create_user_variables.php new file mode 100644 index 0000000..250c18c --- /dev/null +++ b/app/Database/Migrations/20181031062503_create_user_variables.php @@ -0,0 +1,83 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'user_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'data_key' => [ + 'type' => 'VARCHAR', + 'constraint' => 100, + ], + 'data_value' => [ + 'type' => 'TEXT', + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'system' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 0, + ], + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTableUserVariables, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableUserVariables, true); + } +} diff --git a/app/Database/Migrations/20181031063113_create_login_attempts.php b/app/Database/Migrations/20181031063113_create_login_attempts.php new file mode 100644 index 0000000..35b8723 --- /dev/null +++ b/app/Database/Migrations/20181031063113_create_login_attempts.php @@ -0,0 +1,79 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'ip_address' => [ + 'type' => 'VARCHAR', + 'constraint' => 39, + 'default' => 0, + ], + 'user_agent' => [ + 'type' => 'TINYTEXT', + ], + 'count' => [ + 'type' => 'TINYINT', + 'constraint' => 2, + 'default' => 0, + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTableLoginAttempts, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableLoginAttempts, true); + } +} diff --git a/app/Database/Migrations/20181031063642_create_login_tokens.php b/app/Database/Migrations/20181031063642_create_login_tokens.php new file mode 100644 index 0000000..4bc8a12 --- /dev/null +++ b/app/Database/Migrations/20181031063642_create_login_tokens.php @@ -0,0 +1,80 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'user_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'default' => 0, + ], + 'random_hash' => [ + 'type' => 'VARCHAR', + 'constraint' => 255, + ], + 'selector_hash' => [ + 'type' => 'VARCHAR', + 'constraint' => 255, + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'expires_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTableLoginTokens, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableLoginTokens, true); + } +} diff --git a/app/Database/Migrations/20181031064211_create_groups.php b/app/Database/Migrations/20181031064211_create_groups.php new file mode 100644 index 0000000..5786ad7 --- /dev/null +++ b/app/Database/Migrations/20181031064211_create_groups.php @@ -0,0 +1,78 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'name' => [ + 'type' => 'VARCHAR', + 'constraint' => 100, + ], + 'definition' => [ + 'type' => 'TEXT', + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'deleted' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 0, + ], + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTableGroups, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableGroups, true); + } +} diff --git a/app/Database/Migrations/20181031064311_create_group_variables.php b/app/Database/Migrations/20181031064311_create_group_variables.php new file mode 100644 index 0000000..5ddc4d9 --- /dev/null +++ b/app/Database/Migrations/20181031064311_create_group_variables.php @@ -0,0 +1,83 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'group_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'data_key' => [ + 'type' => 'VARCHAR', + 'constraint' => 100, + ], + 'data_value' => [ + 'type' => 'TEXT', + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'system' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 0, + ], + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTableGroupVariables, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableGroupVariables, true); + } +} diff --git a/app/Database/Migrations/20181031064431_create_group_to_user.php b/app/Database/Migrations/20181031064431_create_group_to_user.php new file mode 100644 index 0000000..fb108d1 --- /dev/null +++ b/app/Database/Migrations/20181031064431_create_group_to_user.php @@ -0,0 +1,68 @@ +forge->addField([ + 'group_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'user_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + ]); + $this->forge->addKey(['group_id', 'user_id'], true); + $this->forge->createTable($config->dbTableGroupToUser, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableGroupToUser, true); + } +} diff --git a/app/Database/Migrations/20181031064550_create_group_to_group.php b/app/Database/Migrations/20181031064550_create_group_to_group.php new file mode 100644 index 0000000..6ab0915 --- /dev/null +++ b/app/Database/Migrations/20181031064550_create_group_to_group.php @@ -0,0 +1,68 @@ +forge->addField([ + 'group_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'subgroup_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + ]); + $this->forge->addKey(['group_id', 'subgroup_id'], true); + $this->forge->createTable($config->dbTableGroupToGroup, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTableGroupToGroup, true); + } +} diff --git a/app/Database/Migrations/20181031064714_create_perms.php b/app/Database/Migrations/20181031064714_create_perms.php new file mode 100644 index 0000000..0298561 --- /dev/null +++ b/app/Database/Migrations/20181031064714_create_perms.php @@ -0,0 +1,78 @@ +forge->addField([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'auto_increment' => true, + ], + 'name' => [ + 'type' => 'VARCHAR', + 'constraint' => 100, + ], + 'definition' => [ + 'type' => 'TEXT', + ], + 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP', + 'deleted' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 0, + ], + ]); + $this->forge->addKey('id', true); + $this->forge->createTable($config->dbTablePerms, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTablePerms, true); + } +} diff --git a/app/Database/Migrations/20181031065111_create_perm_to_user.php b/app/Database/Migrations/20181031065111_create_perm_to_user.php new file mode 100644 index 0000000..645c4ac --- /dev/null +++ b/app/Database/Migrations/20181031065111_create_perm_to_user.php @@ -0,0 +1,73 @@ +forge->addField([ + 'perm_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'user_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'state' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 1, + ], + ]); + $this->forge->addKey(['perm_id', 'user_id'], true); + $this->forge->createTable($config->dbTablePermToUser, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTablePermToUser, true); + } +} diff --git a/app/Database/Migrations/20181031065240_create_perm_to_group.php b/app/Database/Migrations/20181031065240_create_perm_to_group.php new file mode 100644 index 0000000..e9fe25d --- /dev/null +++ b/app/Database/Migrations/20181031065240_create_perm_to_group.php @@ -0,0 +1,73 @@ +forge->addField([ + 'perm_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'group_id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + ], + 'state' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => 1, + ], + ]); + $this->forge->addKey(['perm_id', 'user_id'], true); + $this->forge->createTable($config->dbTablePermToGroup, true); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->forge->dropTable($config->dbTablePermToGroup, true); + } +} diff --git a/app/Database/Migrations/20181031072542_create_default_groups.php b/app/Database/Migrations/20181031072542_create_default_groups.php new file mode 100644 index 0000000..afe2dba --- /dev/null +++ b/app/Database/Migrations/20181031072542_create_default_groups.php @@ -0,0 +1,70 @@ + $config->groupAdmin, + 'definition' => 'Administators', + ], + [ + 'name' => $config->groupDefault, + 'definition' => 'Users', + ], + [ + 'name' => $config->groupPublic, + 'definition' => 'Guests', + ], + ]; + + $this->db->table($config->dbTableGroups)->insertBatch($data); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->db->table($config->dbTableGroups)->truncate(); + } +} diff --git a/app/Database/Migrations/20181031072914_create_default_users.php b/app/Database/Migrations/20181031072914_create_default_users.php new file mode 100644 index 0000000..9ce8fb0 --- /dev/null +++ b/app/Database/Migrations/20181031072914_create_default_users.php @@ -0,0 +1,86 @@ + 'admin', + 'email' => 'admin@example.com', + 'password' => password_hash('password123456', $config->passwordHashAlgo, $config->passwordHashOptions), + ], + [ + 'username' => 'user', + 'email' => 'user@example.com', + 'password' => password_hash('password123456', $config->passwordHashAlgo, $config->passwordHashOptions), + ], + ]; + + $this->db->table($config->dbTableUsers)->insertBatch($data); + + $data = [ + [ + 'group_id' => 1, + 'user_id' => 1, + ], + [ + 'group_id' => 2, + 'user_id' => 1, + ], + [ + 'group_id' => 2, + 'user_id' => 2, + ], + ]; + + $this->db->table($config->dbTableGroupToUser)->insertBatch($data); + } + + //-------------------------------------------------------------------- + + /** + * Drops Table + * + * @return void + */ + public function down() + { + $config = new AauthConfig(); + $this->db->table($config->dbTableUsers)->truncate(); + $this->db->table($config->dbTableGroupToUser)->truncate(); + } +}