bp/app/Database/Migrations/2026-01-07-053413_CreateOrg...

54 lines
1.7 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateOrganizationSubscriptionsTable 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,
],
'module_code' => [
'type' => 'VARCHAR',
'constraint' => 50, // 'crm', 'booking', 'proof', 'tasks'
],
'status' => [
'type' => 'ENUM',
'constraint' => ['trial', 'active', 'expired', 'cancelled'],
'default' => 'trial',
],
'expires_at' => [
'type' => 'DATETIME',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
// Организация не может иметь две активные подписки на один модуль одновременно
$this->forge->addUniqueKey(['organization_id', 'module_code']);
$this->forge->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('organization_subscriptions');
}
public function down()
{
$this->forge->dropTable('organization_subscriptions');
}
}