Completed
Push — master ( ca3e5a...8325fc )
by vistart
04:16
created

down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\organization\migrations;
14
15
use rhosocial\user\User;
16
use rhosocial\organization\Organization;
17
use rhosocial\organization\OrganizationLimit;
18
use rhosocial\user\migrations\Migration;
19
20
/**
21
 * Create Organization Limit Table.
22
 *
23
 * This migration is equivalent to:
24
```SQL
25
CREATE TABLE `organization_limit` (
26
`guid` varbinary(16) NOT NULL COMMENT 'GUID',
27
`user_guid` varbinary(16) NOT NULL COMMENT 'User GUID',
28
`limit` int(11) unsigned NOT NULL DEFAULT '10' COMMENT 'Limit',
29
`ip` varbinary(16) NOT NULL DEFAULT '0' COMMENT 'IP Address',
30
`ip_type` tinyint(3) NOT NULL DEFAULT '4' COMMENT 'IP Address Type',
31
`created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At',
32
`updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At',
33
PRIMARY KEY (`guid`),
34
UNIQUE KEY `organization_user_unique` (`user_guid`),
35
CONSTRAINT `organization_user_limit_fk` FOREIGN KEY (`user_guid`) REFERENCES `user` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE
36
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Organization Limit';
37
```
38
 * @package rhosocial\organization\migrations
39
 * @version 1.0
40
 * @author vistart <[email protected]>
41
 */
42
class m170410_073641_createOrganizationLimitTable extends Migration
43
{
44
    public function up()
45
    {
46
        if ($this->db->driverName == 'mysql') {
47
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
48
            $tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Organization Limit'";
49
            $this->createTable(OrganizationLimit::tableName(), [
50
                'guid' => $this->varbinary(16)->notNull()->comment('GUID'),
51
                'user_guid' => $this->varbinary(16)->notNull()->comment('User GUID'),
52
                'limit' => $this->integer(11)->unsigned()->defaultValue(10)->notNull()->comment('Limit'),
53
                'ip' => $this->varbinary(16)->notNull()->defaultValue(0)->comment('IP Address'),
54
                'ip_type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(4)->comment('IP Address Type'),
55
                'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'),
56
                'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'),
57
            ], $tableOptions);
58
        }
59
        $this->addPrimaryKey('organization_limit_guid_pk', OrganizationLimit::tableName(), 'guid');
60
        $this->addForeignKey('organization_user_limit_fk', OrganizationLimit::tableName(), 'user_guid', User::tableName(), 'guid', 'CASCADE', 'CASCADE');
61
        $this->createIndex('organization_user_unique', OrganizationLimit::tableName(), ['user_guid'], true);
62
    }
63
64
    public function down()
65
    {
66
        $this->dropTable(OrganizationLimit::tableName());
67
    }
68
69
    /*
70
    // Use safeUp/safeDown to run migration code within a transaction
71
    public function safeUp()
72
    {
73
    }
74
75
    public function safeDown()
76
    {
77
    }
78
    */
79
}
80