m170411_092857_createMemberLimitTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 38
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 19 2
A down() 0 4 1
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\organization\MemberLimit;
16
use rhosocial\organization\Organization;
17
use rhosocial\user\migrations\Migration;
18
19
/**
20
 * Class m170411_092857_createMemberLimitTable
21
 *
22
 * This migration is equivalent to:
23
```SQL
24
CREATE TABLE `organization_member_limit` (
25
`guid` varbinary(16) NOT NULL COMMENT 'GUID',
26
`organization_guid` varbinary(16) NOT NULL COMMENT 'Organization GUID',
27
`limit` int(11) unsigned NOT NULL DEFAULT '100' COMMENT 'Limit',
28
`ip` varbinary(16) NOT NULL DEFAULT '0' COMMENT 'IP Address',
29
`ip_type` tinyint(3) NOT NULL DEFAULT '4' COMMENT 'IP Address Type',
30
`created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At',
31
`updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At',
32
PRIMARY KEY (`guid`),
33
UNIQUE KEY `member_limit_organization_unique` (`organization_guid`),
34
CONSTRAINT `member_limit_organization_fk` FOREIGN KEY (`organization_guid`) REFERENCES `organization` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE
35
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Member Limit'
36
```
37
 * @package rhosocial\organization\migrations
38
 * @version 1.0
39
 * @author vistart <[email protected]>
40
 */
41
class m170411_092857_createMemberLimitTable extends Migration
42
{
43
    public function up()
44
    {
45
        if ($this->db->driverName == 'mysql') {
46
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
47
            $tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Member Limit'";
48
            $this->createTable(MemberLimit::tableName(), [
49
                'guid' => $this->varbinary(16)->notNull()->comment('GUID'),
50
                'organization_guid' => $this->varbinary(16)->notNull()->comment('Organization GUID'),
51
                'limit' => $this->integer(11)->unsigned()->defaultValue(100)->notNull()->comment('Limit'),
52
                'ip' => $this->varbinary(16)->notNull()->defaultValue(0)->comment('IP Address'),
53
                'ip_type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(4)->comment('IP Address Type'),
54
                'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'),
55
                'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'),
56
            ], $tableOptions);
57
        }
58
        $this->addPrimaryKey('member_limit_guid_pk', MemberLimit::tableName(), 'guid');
59
        $this->addForeignKey('member_limit_organization_fk', MemberLimit::tableName(), 'organization_guid', Organization::tableName(), 'guid', 'CASCADE', 'CASCADE');
60
        $this->createIndex('member_limit_organization_unique', MemberLimit::tableName(), ['organization_guid'], true);
61
    }
62
63
    public function down()
64
    {
65
        $this->dropTable(MemberLimit::tableName());
66
    }
67
68
    /*
69
    // Use safeUp/safeDown to run migration code within a transaction
70
    public function safeUp()
71
    {
72
    }
73
74
    public function safeDown()
75
    {
76
    }
77
    */
78
}
79