Skip to content

Commit

Permalink
Merge pull request #819 from jtojnar/813-upgrade-script
Browse files Browse the repository at this point in the history
Add upgrade script for conversion to utf8mb4
  • Loading branch information
SSilence authored Nov 17, 2016
2 parents 62a2ad2 + c663e18 commit 3ab7e91
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions daos/mysql/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function __construct() {
\F3::set('db', new \DB\SQL(
'mysql:host=' . \F3::get('db_host') . ';port=' . \F3::get('db_port') . ';dbname='.\F3::get('db_database'),
\F3::get('db_username'),
\F3::get('db_password')
\F3::get('db_password'),
array(\PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES utf8mb4;')
));

// create tables if necessary
Expand All @@ -59,7 +60,7 @@ public function __construct() {
updatetime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
author VARCHAR(255),
INDEX (source)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
');
\F3::get('db')->exec('
CREATE TRIGGER insert_updatetime_trigger
Expand Down Expand Up @@ -90,7 +91,7 @@ public function __construct() {
error TEXT,
lastupdate INT,
lastentry INT
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
');
$isNewestSourcesTable = true;
}
Expand All @@ -100,7 +101,7 @@ public function __construct() {
\F3::get('db')->exec('
CREATE TABLE '.\F3::get('db_prefix').'version (
version INT
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
');

\F3::get('db')->exec('
Expand All @@ -111,7 +112,7 @@ public function __construct() {
CREATE TABLE '.\F3::get('db_prefix').'tags (
tag TEXT NOT NULL,
color VARCHAR(7) NOT NULL
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
');

if($isNewestSourcesTable===false) {
Expand Down Expand Up @@ -189,6 +190,15 @@ public function __construct() {
INSERT INTO '.\F3::get('db_prefix').'version (version) VALUES (9);
');
}
if(strnatcmp($version, "10") < 0) {
\F3::get('db')->exec(array(
'ALTER TABLE `' . \F3::get('db_prefix') . 'items` CONVERT TO CHARACTER SET utf8mb4;',
'ALTER TABLE `' . \F3::get('db_prefix') . 'sources` CONVERT TO CHARACTER SET utf8mb4;',
'ALTER TABLE `' . \F3::get('db_prefix') . 'tags` CONVERT TO CHARACTER SET utf8mb4;',
'ALTER TABLE `' . \F3::get('db_prefix') . 'version` CONVERT TO CHARACTER SET utf8mb4;',
'INSERT INTO `' . \F3::get('db_prefix') . 'version` (version) VALUES (10);'
));
}
}

// just initialize once
Expand Down

0 comments on commit 3ab7e91

Please sign in to comment.