|
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\Profile; |
|
17
|
|
|
use rhosocial\user\migrations\Migration; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Create Organization Table. |
|
21
|
|
|
* |
|
22
|
|
|
* This migration is equivalent to: |
|
23
|
|
|
```SQL |
|
24
|
|
|
CREATE TABLE `organization_profile` ( |
|
25
|
|
|
`guid` varbinary(16) NOT NULL COMMENT 'Organization GUID', |
|
26
|
|
|
`nickname` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Nickname', |
|
27
|
|
|
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Name', |
|
28
|
|
|
`gravatar_type` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Gravatar Type', |
|
29
|
|
|
`gravatar` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Gravatar', |
|
30
|
|
|
`timezone` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'UTC' COMMENT 'Timezone', |
|
31
|
|
|
`description` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Description', |
|
32
|
|
|
`created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At', |
|
33
|
|
|
`updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At', |
|
34
|
|
|
PRIMARY KEY (`guid`), |
|
35
|
|
|
KEY `organization_nickname_normal` (`nickname`), |
|
36
|
|
|
KEY `organization_name_normal` (`name`), |
|
37
|
|
|
CONSTRAINT `organization_profile_fk` FOREIGN KEY (`guid`) REFERENCES `organization` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE |
|
38
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Organization Profile'; |
|
39
|
|
|
``` |
|
40
|
|
|
* @version 1.0 |
|
41
|
|
|
* @author vistart <[email protected]> |
|
42
|
|
|
*/ |
|
43
|
|
|
class m170327_071501_createOrganizationProfileTable extends Migration |
|
44
|
|
|
{ |
|
45
|
|
|
public function up() |
|
46
|
|
|
{ |
|
47
|
|
|
if ($this->db->driverName === 'mysql') { |
|
48
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
|
49
|
|
|
$tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Organization Profile'"; |
|
50
|
|
|
$this->createTable(Profile::tableName(), [ |
|
51
|
|
|
'guid' => $this->varbinary(16)->notNull()->comment('Organization GUID'), |
|
52
|
|
|
'nickname' => $this->varchar(255)->notNull()->defaultValue('')->comment('Nickname'), |
|
53
|
|
|
'name' => $this->varchar(255)->notNull()->defaultValue('')->comment('Name'), |
|
54
|
|
|
'gravatar_type' => $this->smallInteger()->notNull()->defaultValue(0)->comment('Gravatar Type'), |
|
55
|
|
|
'gravatar'=> $this->varchar(255)->notNull()->defaultValue('')->comment('Gravatar'), |
|
56
|
|
|
'timezone' => $this->varchar(255)->charset('utf8')->collate('utf8_unicode_ci')->notNull()->defaultValue('UTC')->comment('Timezone'), |
|
57
|
|
|
'description' => $this->text()->notNull()->comment('Description'), |
|
58
|
|
|
'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'), |
|
59
|
|
|
'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'), |
|
60
|
|
|
], $tableOptions); |
|
61
|
|
|
} |
|
62
|
|
|
$this->addPrimaryKey('organization_guid_profile_pk', Profile::tableName(), 'guid'); |
|
63
|
|
|
$this->addForeignKey('organization_profile_fk', Profile::tableName(), 'guid', Organization::tableName(), 'guid', 'CASCADE', 'CASCADE'); |
|
64
|
|
|
$this->createIndex('organization_nickname_normal', Profile::tableName(), 'nickname'); |
|
65
|
|
|
$this->createIndex('organization_name_normal', Profile::tableName(), 'name'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function down() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->dropTable(Profile::tableName()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/* |
|
74
|
|
|
// Use safeUp/safeDown to run migration code within a transaction |
|
75
|
|
|
public function safeUp() |
|
76
|
|
|
{ |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function safeDown() |
|
80
|
|
|
{ |
|
81
|
|
|
} |
|
82
|
|
|
*/ |
|
83
|
|
|
} |
|
84
|
|
|
|