71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
/**
|
|
* Migration для создания таблицы подписок организаций на тарифы
|
|
* Использует ту же структуру что и organization_subscriptions для модулей
|
|
*/
|
|
class CreateOrganizationPlanSubscriptionsTable 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,
|
|
],
|
|
'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');
|
|
}
|
|
}
|