Initial commit
This commit is contained in:
45
console/migrations/m221203_160610_create_user_table.php
Normal file
45
console/migrations/m221203_160610_create_user_table.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use common\models\User;
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%user}}`.
|
||||
*/
|
||||
class m221203_160610_create_user_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$tableOptions = null;
|
||||
if ($this->db->driverName === 'mysql') {
|
||||
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
|
||||
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
|
||||
}
|
||||
|
||||
$this->createTable('{{%user}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'auth_key' => $this->string(32)->notNull(),
|
||||
'password_hash' => $this->string()->notNull(),
|
||||
'password_reset_token' => $this->string()->unique(),
|
||||
'verification_token' => $this->string()->defaultValue(null),
|
||||
'first_name' => $this->string(64),
|
||||
'email' => $this->string()->notNull()->unique(),
|
||||
'status' => $this->smallInteger()->notNull()->defaultValue(User::STATUS_UNVERIFIED),
|
||||
'welcome_email_sent' => $this->boolean()->defaultValue(false),
|
||||
'created_at' => $this->integer()->notNull(),
|
||||
'updated_at' => $this->integer()->notNull(),
|
||||
|
||||
], $tableOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropTable('{{%user}}');
|
||||
}
|
||||
}
|
||||
87
console/migrations/m230120_214209_init_rbac.php
Normal file
87
console/migrations/m230120_214209_init_rbac.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m230120_214209_init_rbac
|
||||
*/
|
||||
class m230120_214209_init_rbac extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$auth = Yii::$app->authManager;
|
||||
|
||||
/**
|
||||
* Permissions for future use?
|
||||
* Maybe...
|
||||
*/
|
||||
// add "view meal" permission
|
||||
$viewMeal = $auth->createPermission('viewMeal');
|
||||
$viewMeal->description = 'View own meal records';
|
||||
$auth->add($viewMeal);
|
||||
|
||||
// add "create meal" permission
|
||||
$createMeal = $auth->createPermission('createMeal');
|
||||
$createMeal->description = 'Create a new meal record';
|
||||
$auth->add($createMeal);
|
||||
|
||||
// add "update meal" permission
|
||||
$updateMeal = $auth->createPermission('updateMeal');
|
||||
$updateMeal->description = 'Update own meal records';
|
||||
$auth->add($updateMeal);
|
||||
|
||||
// add "delete meal" permission
|
||||
$deleteMeal = $auth->createPermission('deleteMeal');
|
||||
$deleteMeal->description = 'Delete own meal records';
|
||||
$auth->add($deleteMeal);
|
||||
|
||||
|
||||
// add "view all meals" permission (for admin)
|
||||
$viewAllMeals = $auth->createPermission('viewAllMeals');
|
||||
$viewAllMeals->description = 'View all meal records';
|
||||
$auth->add($viewAllMeals);
|
||||
|
||||
// add "update all meals" permission (for admin)
|
||||
$updateAllMeals = $auth->createPermission('updateAllMeals');
|
||||
$updateAllMeals->description = 'Update any meal record';
|
||||
$auth->add($updateAllMeals);
|
||||
|
||||
// add "delete all meals" permission (for admin)
|
||||
$deleteAllMeals = $auth->createPermission('deleteAllMeals');
|
||||
$deleteAllMeals->description = 'Delete any meal record';
|
||||
$auth->add($deleteAllMeals);
|
||||
|
||||
// Add roles
|
||||
$user = $auth->createRole('user');
|
||||
$auth->add($user);
|
||||
|
||||
$admin = $auth->createRole('admin');
|
||||
$auth->add($admin);
|
||||
|
||||
|
||||
// Add permissions to roles (crucially important):
|
||||
$auth->addChild($user, $viewMeal);
|
||||
$auth->addChild($user, $createMeal);
|
||||
$auth->addChild($user, $updateMeal);
|
||||
$auth->addChild($user, $deleteMeal);
|
||||
|
||||
$auth->addChild($admin, $viewMeal);
|
||||
$auth->addChild($admin, $createMeal);
|
||||
$auth->addChild($admin, $updateMeal);
|
||||
$auth->addChild($admin, $deleteMeal);
|
||||
$auth->addChild($admin, $viewAllMeals);
|
||||
$auth->addChild($admin, $updateAllMeals);
|
||||
$auth->addChild($admin, $deleteAllMeals);
|
||||
|
||||
// Assign roles to users. 1 and 2 are IDs returned by IdentityInterface::getId()
|
||||
// usually implemented in your User model.
|
||||
$auth->assign($admin, 1);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$auth = Yii::$app->authManager;
|
||||
|
||||
$auth->removeAll();
|
||||
}
|
||||
}
|
||||
47
console/migrations/m230210_155341_queue_table.php
Normal file
47
console/migrations/m230210_155341_queue_table.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m230210_155341_queue_table
|
||||
*/
|
||||
class m230210_155341_queue_table extends Migration
|
||||
{
|
||||
public $tableName = '{{%queue}}';
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$tableOptions = null;
|
||||
if ($this->db->driverName === 'mysql') {
|
||||
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
|
||||
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
|
||||
}
|
||||
|
||||
$this->createTable($this->tableName, [
|
||||
'id' => $this->primaryKey(),
|
||||
'channel' => $this->string()->notNull(),
|
||||
'job' => $this->binary()->notNull(),
|
||||
'pushed_at' => $this->integer()->notNull(),
|
||||
'ttr' => $this->integer()->notNull(),
|
||||
'delay' => $this->integer()->notNull(),
|
||||
'priority' => $this->integer()->unsigned()->notNull()->defaultValue(1024),
|
||||
'reserved_at' => $this->integer(),
|
||||
'attempt' => $this->integer(),
|
||||
'done_at' => $this->integer(),
|
||||
], $tableOptions);
|
||||
$this->createIndex('channel', $this->tableName, 'channel');
|
||||
$this->createIndex('reserved_at', $this->tableName, 'reserved_at');
|
||||
$this->createIndex('priority', $this->tableName, 'priority');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropTable($this->tableName);
|
||||
}
|
||||
|
||||
}
|
||||
36
console/migrations/m250219_133939_create_meal_table.php
Normal file
36
console/migrations/m250219_133939_create_meal_table.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%meal}}`.
|
||||
*/
|
||||
class m250219_133939_create_meal_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%meal}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'file_name' => $this->string()->notNull(),
|
||||
'calories' => $this->integer()->notNull(),
|
||||
'protein' => $this->integer()->notNull(),
|
||||
'fat' => $this->integer()->notNull(),
|
||||
'carbohydrates' => $this->integer()->notNull(),
|
||||
'fiber' => $this->integer()->notNull(),
|
||||
'meal' => $this->integer()->notNull(),
|
||||
'created_at' => $this->integer()->notNull(),
|
||||
'updated_at' => $this->integer()->notNull(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropTable('{{%meal}}');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user