Skip to content

Commit

Permalink
Use migrations to create table
Browse files Browse the repository at this point in the history
  • Loading branch information
hakito committed May 2, 2020
1 parent b1c3345 commit 6c461b4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 20 deletions.
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,13 @@ If you are using composer simply add it with:
composer require hakito/cakephp-paypal-rest-plugin
```

Model
-----
Creating tables
---------------

Create the database PayPalPayments table with the following command:

Add the following table to your database.

```sql
CREATE TABLE IF NOT EXISTS `PayPalPayments` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
`payment_id` varchar(50) DEFAULT NULL,
`payment_state` enum('created','approved','failed','canceled','expired','pending') DEFAULT NULL,
`sale_state` enum('pending','completed','refunded','partially_refunded') DEFAULT NULL,
`remittance_identifier` varchar(100) NOT NULL,
`remitted_moment` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `payment_id` (`payment_id`),
KEY `sale_state` (`sale_state`,`remitted_moment`),
KEY `payment_state` (`payment_state`),
KEY `payment_state_2` (`payment_state`,`sale_state`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```bash
bin/cake migrations migrate -p PayPal
```

Configuration
Expand Down
86 changes: 86 additions & 0 deletions config/Migrations/20200502064752_Initial.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
use Migrations\AbstractMigration;

class Initial extends AbstractMigration
{

public $autoId = false;

public function up()
{

$this->table('PayPalPayments')
->addColumn('id', 'integer', [
'autoIncrement' => true,
'default' => null,
'limit' => 10,
'null' => false,
'signed' => false,
])
->addPrimaryKey(['id'])
->addColumn('created', 'datetime', [
'default' => null,
'limit' => null,
'null' => false,
])
->addColumn('updated', 'datetime', [
'default' => null,
'limit' => null,
'null' => false,
])
->addColumn('payment_id', 'string', [
'default' => null,
'limit' => 50,
'null' => true,
])
->addColumn('payment_state', 'string', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('sale_state', 'string', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('remittance_identifier', 'string', [
'default' => null,
'limit' => 100,
'null' => false,
])
->addColumn('remitted_moment', 'datetime', [
'default' => null,
'limit' => null,
'null' => true,
])
->addIndex(
[
'payment_id',
],
['unique' => true]
)
->addIndex(
[
'sale_state',
'remitted_moment',
]
)
->addIndex(
[
'payment_state',
]
)
->addIndex(
[
'payment_state',
'sale_state',
]
)
->create();
}

public function down()
{
$this->table('PayPalPayments')->drop()->save();
}
}

0 comments on commit 6c461b4

Please sign in to comment.