61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class CreateOrganizationUsersTable extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
$this->forge->addField([
|
|
'id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
'auto_increment' => true,
|
|
],
|
|
'organization_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
],
|
|
'user_id' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
],
|
|
'role' => [
|
|
'type' => 'ENUM',
|
|
'constraint' => ['owner', 'admin', 'manager', 'guest'],
|
|
'default' => 'manager',
|
|
],
|
|
'status' => [
|
|
'type' => 'ENUM',
|
|
'constraint' => ['active', 'invited', 'blocked'],
|
|
'default' => 'active',
|
|
],
|
|
'joined_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'created_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
|
|
// Защита от дублей: один юзер не может быть дважды в одной организации
|
|
$this->forge->addUniqueKey(['organization_id', 'user_id']);
|
|
|
|
$this->forge->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE');
|
|
$this->forge->addForeignKey('user_id', 'users', 'id', 'CASCADE', 'CASCADE');
|
|
$this->forge->createTable('organization_users');
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
$this->forge->dropTable('organization_users');
|
|
}
|
|
} |