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'); } }