m170327_031029_createOrganizationTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 21 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\Organization;
16
use rhosocial\user\migrations\Migration;
17
18
/**
19
 * Create Organization Table.
20
 *
21
 * This migration is equivalent to:
22
```SQL
23
CREATE TABLE `organization` (
24
  `guid` varbinary(16) NOT NULL COMMENT 'Organization GUID',
25
  `id` varchar(16) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Organization ID No.',
26
  `ip` varbinary(16) NOT NULL DEFAULT '0' COMMENT 'IP Address',
27
  `ip_type` tinyint(3) NOT NULL DEFAULT '4' COMMENT 'IP Address Type',
28
  `parent_guid` varbinary(16) NOT NULL DEFAULT '' COMMENT 'Parent',
29
  `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At',
30
  `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At',
31
  `status` tinyint(3) NOT NULL DEFAULT '1' COMMENT 'Status',
32
  `type` tinyint(3) NOT NULL DEFAULT '1' COMMENT 'Type',
33
  PRIMARY KEY (`guid`),
34
  UNIQUE KEY `organization_id_unique` (`id`),
35
  KEY `organization_created_at_normal` (`created_at`)
36
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Organization';
37
```
38
 * @version 1.0
39
 * @author vistart <[email protected]>
40
 */
41
class m170327_031029_createOrganizationTable 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='Organization'";
48
            $this->createTable(Organization::tableName(), [
49
                'guid' => $this->varbinary(16)->notNull()->comment('Organization GUID'),
50
                'id' => $this->varchar(16)->notNull()->collate('utf8_unicode_ci')->comment('Organization ID No.'),
51
                'ip' => $this->varbinary(16)->notNull()->defaultValue(0)->comment('IP Address'),
52
                'ip_type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(4)->comment('IP Address Type'),
53
                'parent_guid' => $this->varbinary(16)->notNull()->defaultValue('')->comment('Parent'),
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
                'status' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(1)->comment('Status'),
57
                'type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(Organization::TYPE_ORGANIZATION)->comment('Type'),
58
            ], $tableOptions);
59
        }
60
        $this->addPrimaryKey('organization_guid_pk', Organization::tableName(), 'guid');
61
        $this->createIndex('organization_id_unique', Organization::tableName(), 'id', true);
62
        $this->createIndex('organization_created_at_normal', Organization::tableName(), 'created_at');
63
    }
64
65
    public function down()
66
    {
67
        $this->dropTable(Organization::tableName());
68
    }
69
70
    /*
71
    // Use safeUp/safeDown to run migration code within a transaction
72
    public function safeUp()
73
    {
74
    }
75
76
    public function safeDown()
77
    {
78
    }
79
    */
80
}
81