forge->addField([ 'id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true, ], 'organization_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, ], 'plan_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, ], 'status' => [ 'type' => 'ENUM', 'constraint' => ['trial', 'active', 'expired', 'cancelled'], 'default' => 'trial', ], 'trial_ends_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'expires_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'created_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'updated_at' => [ 'type' => 'DATETIME', 'null' => true, ], ]); $this->forge->addKey('id', true); // Организация не может иметь две активные подписки на один тариф одновременно $this->forge->addUniqueKey(['organization_id', 'plan_id']); $this->forge->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE'); $this->forge->addForeignKey('plan_id', 'plans', 'id', 'CASCADE', 'CASCADE'); $this->forge->createTable('organization_plan_subscriptions'); } public function down() { $this->forge->dropTable('organization_plan_subscriptions'); } }