Completed
Pull Request — master (#265)
by
unknown
08:02
created

Initial::up()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 37
nc 1
nop 0
dl 0
loc 40
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/skeleton
5
 */
6
7
use Phinx\Migration\AbstractMigration;
8
9
/**
10
 * InitDb
11
 */
12
class Initial extends AbstractMigration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * Migrate Up.
16
     */
17
    public function up()
18
    {
19
        $this->execute('SET storage_engine=INNODB;');
20
        $this->execute('CREATE TABLE users (id BIGINT(20) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT, login VARCHAR(255), email VARCHAR(255), created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, updated TIMESTAMP NOT NULL, status VARCHAR(32) DEFAULT \'disabled\' NOT NULL);');
21
        $this->execute('CREATE UNIQUE INDEX users_login_uindex ON users (login);');
22
        $this->execute('CREATE UNIQUE INDEX users_email_uindex ON users (email);');
23
        $this->execute('CREATE TABLE users_actions (userId BIGINT(20) unsigned NOT NULL, code VARCHAR(32) NOT NULL, action VARCHAR(32) NOT NULL, params LONGTEXT, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, expired TIMESTAMP NOT NULL, CONSTRAINT users_actions_userId_code_pk PRIMARY KEY (userId, code), CONSTRAINT users_actions_users_id_fk FOREIGN KEY (userId) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE);');
24
        $this->execute('CREATE UNIQUE INDEX users_actions_userId_action_uindex ON users_actions (userId, action);');
25
        $this->execute('CREATE TABLE auth ( userId BIGINT(20) unsigned NOT NULL, provider VARCHAR(64) NOT NULL, foreignKey VARCHAR(255) NOT NULL, token VARCHAR(64) NOT NULL, tokenSecret VARCHAR(64) NOT NULL, tokenType VARCHAR(32) NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, updated TIMESTAMP NOT NULL, expired TIMESTAMP NOT NULL, CONSTRAINT auth_userId_provider_pk PRIMARY KEY (userId, provider), CONSTRAINT auth_users_id_fk FOREIGN KEY (userId) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE);');
26
        $this->execute('CREATE TABLE acl_roles ( id INT(10) unsigned NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT acl_roles_id_name_pk PRIMARY KEY (id, name));');
27
        $this->execute('CREATE UNIQUE INDEX acl_roles_name_uindex ON acl_roles (name);');
28
        $this->execute('CREATE TABLE acl_privileges ( roleId INT(10) unsigned NOT NULL, module VARCHAR(32) NOT NULL, privilege VARCHAR(32) NOT NULL, CONSTRAINT acl_privileges_acl_roles_id_fk FOREIGN KEY (roleId) REFERENCES acl_roles (id) ON DELETE CASCADE ON UPDATE CASCADE);');
29
        $this->execute('CREATE UNIQUE INDEX acl_privileges_roleId_module_privilege_uindex ON acl_privileges (roleId, module, privilege);');
30
        $this->execute('CREATE TABLE acl_users_roles ( userId BIGINT(20) unsigned NOT NULL, roleId INT(10) unsigned NOT NULL, CONSTRAINT acl_users_roles_userId_roleId_pk PRIMARY KEY (userId, roleId), CONSTRAINT acl_users_roles_users_id_fk FOREIGN KEY (userId) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT acl_users_roles_acl_roles_id_fk FOREIGN KEY (roleId) REFERENCES acl_roles (id) ON DELETE CASCADE ON UPDATE CASCADE);');
31
        $this->execute('CREATE TABLE pages ( id INT(10) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT, userId BIGINT(20) unsigned, title LONGTEXT NOT NULL, alias VARCHAR(255) NOT NULL, content LONGTEXT, keywords LONGTEXT, description LONGTEXT, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, updated TIMESTAMP NOT NULL, CONSTRAINT pages_users_id_fk FOREIGN KEY (userId) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE);');
32
        $this->execute('CREATE UNIQUE INDEX pages_alias_uindex ON pages (alias);');
33
        $this->execute('CREATE TABLE com_settings ( id INT(10) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT, alias VARCHAR(255) NOT NULL, options LONGTEXT, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, updated TIMESTAMP NOT NULL, countPerPage SMALLINT(6) DEFAULT \'10\' NOT NULL, relatedTable VARCHAR(64));');
34
        $this->execute('CREATE UNIQUE INDEX com_settings_alias_uindex ON com_settings (alias);');
35
        $this->execute('CREATE TABLE com_content ( id BIGINT(20) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT, settingsId INT(10) unsigned NOT NULL, foreignKey INT(10) unsigned NOT NULL, userId BIGINT(20) unsigned NOT NULL, parentId BIGINT(20) unsigned, content LONGTEXT, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, updated TIMESTAMP NOT NULL,  status VARCHAR(255) DEFAULT \'active\' NOT NULL, CONSTRAINT com_content_com_settings_id_fk FOREIGN KEY (settingsId) REFERENCES com_settings (id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT com_content_users_id_fk FOREIGN KEY (userId) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT com_content_com_content_id_fk FOREIGN KEY (parentId) REFERENCES com_content (id) ON DELETE CASCADE ON UPDATE CASCADE);');
36
        $this->execute('CREATE INDEX comments_target ON com_content (settingsId, foreignKey);');
37
38
        $this->execute('LOCK TABLES `users` WRITE;');
39
        $this->execute('INSERT INTO `users` (`id`, `login`, `email`, `created`, `updated`, `status`) VALUES (1,\'system\',NULL,\'2012-11-09 07:37:58\',NULL,\'disabled\'), (2,\'admin\',NULL,\'2012-11-09 07:38:41\',NULL,\'active\');');
40
        $this->execute('UNLOCK TABLES;');
41
        $this->execute('LOCK TABLES `acl_roles` WRITE;');
42
        $this->execute('INSERT INTO `acl_roles` (`id`, `name`, `created`) VALUES (1,\'system\',\'2012-11-09 07:37:31\'), (2,\'admin\',\'2012-11-09 07:37:33\'), (3,\'member\',\'2012-11-09 07:37:37\'), (4,\'guest\',\'2012-11-09 07:37:44\');');
43
        $this->execute('UNLOCK TABLES;');
44
        $this->execute('LOCK TABLES `acl_privileges` WRITE;');
45
        $this->execute('INSERT INTO `acl_privileges` (`roleId`, `module`, `privilege`) VALUES (2,\'acl\',\'Management\'), (2,\'acl\',\'View\'), (2,\'cache\',\'Management\'), (2,\'dashboard\',\'Dashboard\'), (2,\'pages\',\'Management\'), (2,\'system\',\'Info\'), (2,\'users\',\'EditEmail\'), (2,\'users\',\'EditPassword\'), (2,\'users\',\'Management\'), (2,\'users\',\'ViewProfile\'), (3,\'users\',\'EditEmail\'), (3,\'users\',\'EditPassword\'), (3,\'users\',\'ViewProfile\'), (4,\'users\',\'ViewProfile\');');
46
        $this->execute('UNLOCK TABLES;');
47
        $this->execute('LOCK TABLES `acl_users_roles` WRITE;');
48
        $this->execute('INSERT INTO `acl_users_roles` (`userId`, `roleId`) VALUES (1,1), (2,2);');
49
        $this->execute('UNLOCK TABLES;');
50
        $this->execute('LOCK TABLES `auth` WRITE;');
51
        $this->execute('INSERT INTO `auth` (`userId`, `provider`, `foreignKey`, `token`, `tokenSecret`, `tokenType`, `created`) VALUES (2,\'equals\',\'admin\',\'$2y$10$4a454775178c3f89d510fud2T.xtw01Ir.Jo.91Dr3nL2sz3OyVpK\',\'\',\'access\',\'2012-11-09 07:40:46\');');
52
        $this->execute('UNLOCK TABLES;');
53
        $this->execute('LOCK TABLES `pages` WRITE;');
54
        $this->execute('INSERT INTO `pages` (`id`, `title`, `alias`, `content`, `keywords`, `description`, `created`, `updated`, `userId`) VALUES (1,\'About Bluz Framework\',\'about\',\'<p>Bluz Lightweight PHP Framework!</p>\',\'about bluz framework\',\'About Bluz\',\'2012-04-09 18:34:03\',\'2014-05-12 11:01:03\', 1);');
55
        $this->execute('UNLOCK TABLES;');
56
    }
57
    /**
58
     * Migrate Down.
59
     */
60
    public function down()
61
    {
62
        $this->dropTable('com_content');
63
        $this->dropTable('com_settings');
64
        $this->dropTable('pages');
65
        $this->dropTable('acl_users_roles');
66
        $this->dropTable('acl_privileges');
67
        $this->dropTable('acl_roles');
68
        $this->dropTable('auth');
69
        $this->dropTable('users_actions');
70
        $this->dropTable('users');
71
    }
72
}
73