|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use Phinx\Migration\AbstractMigration; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class CreateTokensTable |
|
9
|
|
|
*/ |
|
10
|
|
|
final class CreateSubscriptionsTable extends AbstractMigration |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Change Method. |
|
14
|
|
|
* |
|
15
|
|
|
* Write your reversible migrations using this method. |
|
16
|
|
|
* |
|
17
|
|
|
* More information on writing migrations is available here: |
|
18
|
|
|
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method |
|
19
|
|
|
* |
|
20
|
|
|
* Remember to call "create()" or "update()" and NOT "save()" when working |
|
21
|
|
|
* with the Table class. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function change(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$table_name = \ByTIC\Payments\Utility\PaymentsModels::subscriptions()->getTable(); |
|
26
|
|
|
$exists = $this->hasTable($table_name); |
|
27
|
|
|
if ($exists) { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$table = $this->table($table_name) |
|
32
|
|
|
->addColumn('id_method', 'biginteger') |
|
33
|
|
|
->addColumn('id_token', 'biginteger') |
|
34
|
|
|
->addColumn('id_last_transaction', 'biginteger') |
|
35
|
|
|
->addColumn('customer_id', 'biginteger') |
|
36
|
|
|
->addColumn('customer_type', 'string') |
|
37
|
|
|
->addColumn('status', 'enum', ['values' => ['not_started', 'active', 'completed', 'canceled']]) |
|
38
|
|
|
->addColumn('billing_period', 'enum', ['values' => ['daily', 'weekly', 'monthly', 'yearly']]) |
|
39
|
|
|
->addColumn('billing_interval', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]) |
|
40
|
|
|
->addColumn('billing_count', 'integer', |
|
41
|
|
|
['null' => true, 'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]) |
|
42
|
|
|
->addColumn('start_at', 'date', ['null' => true]) |
|
43
|
|
|
->addColumn('cancel_at', 'date', ['null' => true]) |
|
44
|
|
|
->addColumn('ended_at', 'date', ['null' => true]) |
|
45
|
|
|
->addColumn('charge_at', 'date', ['null' => true]) |
|
46
|
|
|
->addColumn('charge_attempts', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]) |
|
47
|
|
|
->addColumn('charge_count', 'integer', |
|
48
|
|
|
['null' => true, 'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]) |
|
49
|
|
|
->addColumn('charge_method', 'string') |
|
50
|
|
|
->addColumn('metadata', 'json', ['null' => true]) |
|
51
|
|
|
->addColumn('modified', 'timestamp', [ |
|
52
|
|
|
'default' => 'CURRENT_TIMESTAMP', |
|
53
|
|
|
'update' => 'CURRENT_TIMESTAMP', |
|
54
|
|
|
]) |
|
55
|
|
|
->addColumn('created', 'timestamp', [ |
|
56
|
|
|
'default' => 'CURRENT_TIMESTAMP', |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
|
|
$table->addIndex(['id_method']); |
|
60
|
|
|
$table->addIndex(['id_token']); |
|
61
|
|
|
$table->addIndex(['id_last_transaction']); |
|
62
|
|
|
$table->addIndex(['customer_id', 'customer_type']); |
|
63
|
|
|
$table->addIndex(['status']); |
|
64
|
|
|
$table->addIndex(['start_at']); |
|
65
|
|
|
$table->addIndex(['cancel_at']); |
|
66
|
|
|
$table->addIndex(['ended_at']); |
|
67
|
|
|
$table->addIndex(['charge_at']); |
|
68
|
|
|
|
|
69
|
|
|
$table->save(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|