|
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\organization\Member; |
|
17
|
|
|
use rhosocial\user\User; |
|
18
|
|
|
use rhosocial\user\migrations\Migration; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
* This migration is equvalent to: |
|
23
|
|
|
```SQL |
|
24
|
|
|
CREATE TABLE `organization_member` ( |
|
25
|
|
|
`guid` varbinary(16) NOT NULL COMMENT 'Member GUID', |
|
26
|
|
|
`id` varchar(8) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Member ID', |
|
27
|
|
|
`organization_guid` varbinary(16) NOT NULL COMMENT 'Organization GUID', |
|
28
|
|
|
`user_guid` varbinary(16) NOT NULL COMMENT 'User GUID', |
|
29
|
|
|
`nickname` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Nickname', |
|
30
|
|
|
`role` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Role in organization', |
|
31
|
|
|
`description` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Description', |
|
32
|
|
|
`ip` varbinary(16) NOT NULL DEFAULT '0' COMMENT 'IP Address', |
|
33
|
|
|
`ip_type` tinyint(3) NOT NULL DEFAULT '4' COMMENT 'IP Address Type', |
|
34
|
|
|
`created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At', |
|
35
|
|
|
`updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At', |
|
36
|
|
|
PRIMARY KEY (`guid`), |
|
37
|
|
|
UNIQUE KEY `organization_member_unique` (`id`,`organization_guid`), |
|
38
|
|
|
UNIQUE KEY `organization_user_unique` (`organization_guid`,`user_guid`), |
|
39
|
|
|
KEY `member_user_fk` (`user_guid`), |
|
40
|
|
|
KEY `member_created_at_normal` (`created_at`), |
|
41
|
|
|
CONSTRAINT `member_organization_fk` FOREIGN KEY (`organization_guid`) REFERENCES `organization` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE, |
|
42
|
|
|
CONSTRAINT `member_user_fk` FOREIGN KEY (`user_guid`) REFERENCES `user` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE |
|
43
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Organization Member'; |
|
44
|
|
|
``` |
|
45
|
|
|
* @version 1.0 |
|
46
|
|
|
* @author vistart <[email protected]> |
|
47
|
|
|
*/ |
|
48
|
|
|
class m170327_111508_createOrganizationMemberTable extends Migration |
|
49
|
|
|
{ |
|
50
|
|
|
public function up() |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->db->driverName === 'mysql') { |
|
53
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
|
54
|
|
|
$tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Organization Member'"; |
|
55
|
|
|
$this->createTable(Member::tableName(), [ |
|
56
|
|
|
'guid' => $this->varbinary(16)->notNull()->comment('Member GUID'), |
|
57
|
|
|
'id' => $this->varchar(8)->notNull()->defaultValue('')->comment('Member ID'), |
|
58
|
|
|
'organization_guid' => $this->varbinary(16)->notNull()->comment('Organization GUID'), |
|
59
|
|
|
'user_guid' => $this->varbinary(16)->notNull()->comment('User GUID'), |
|
60
|
|
|
'nickname' => $this->varchar(255)->notNull()->defaultValue('')->comment('Nickname'), |
|
61
|
|
|
'role' => $this->varchar(255)->notNull()->defaultValue('')->comment('Role in organization'), |
|
62
|
|
|
'position' => $this->varchar(255)->notNull()->defaultValue('')->comment('Position'), |
|
63
|
|
|
'description' => $this->text()->notNull()->comment('Description'), |
|
64
|
|
|
'ip' => $this->varbinary(16)->notNull()->defaultValue(0)->comment('IP Address'), |
|
65
|
|
|
'ip_type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(4)->comment('IP Address Type'), |
|
66
|
|
|
'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'), |
|
67
|
|
|
'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'), |
|
68
|
|
|
], $tableOptions); |
|
69
|
|
|
} |
|
70
|
|
|
$this->addPrimaryKey('organization_member_pk', Member::tableName(), 'guid'); |
|
71
|
|
|
$this->addForeignKey('member_organization_fk', Member::tableName(), 'organization_guid', Organization::tableName(), 'guid', 'CASCADE', 'CASCADE'); |
|
72
|
|
|
$this->addForeignKey('member_user_fk', Member::tableName(), 'user_guid', User::tableName(), 'guid', 'CASCADE', 'CASCADE'); |
|
73
|
|
|
$this->createIndex('organization_member_unique', Member::tableName(), ['id', 'organization_guid'], true); |
|
74
|
|
|
$this->createIndex('organization_user_unique', Member::tableName(), ['organization_guid', 'user_guid'], true); |
|
75
|
|
|
$this->createIndex('member_created_at_normal', Member::tableName(), 'created_at'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function down() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->dropTable(Member::tableName()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/* |
|
84
|
|
|
// Use safeUp/safeDown to run migration code within a transaction |
|
85
|
|
|
public function safeUp() |
|
86
|
|
|
{ |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function safeDown() |
|
90
|
|
|
{ |
|
91
|
|
|
} |
|
92
|
|
|
*/ |
|
93
|
|
|
} |
|
94
|
|
|
|