Update to correct collation mode

This commit is contained in:
Matthew Exon 2022-10-02 20:18:48 +02:00
parent 70153bde61
commit a21413dce3
2 changed files with 19 additions and 7 deletions

View file

@ -6,11 +6,11 @@ CREATE TABLE IF NOT EXISTS `retriever_rule` (
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
KEY `contact-id` (`contact-id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `retriever_item` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`item-uri` varchar(800) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`item-uri` varbinary(255) NOT NULL,
`item-uid` int(10) unsigned NOT NULL DEFAULT '0',
`contact-id` int(10) unsigned NOT NULL DEFAULT '0',
`resource` int(11) NOT NULL,
@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `retriever_item` (
KEY `item-uid` (`item-uid`),
KEY `all` (`item-uri`, `item-uid`, `contact-id`),
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `retriever_resource` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
@ -28,15 +28,15 @@ CREATE TABLE IF NOT EXISTS `retriever_resource` (
`contact-id` int(10) unsigned NOT NULL DEFAULT '0',
`type` char(255) NULL DEFAULT NULL,
`binary` int(1) NOT NULL DEFAULT 0,
`url` varchar(800) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`url` varbinary(800) NOT NULL,
`created` timestamp NOT NULL DEFAULT now(),
`completed` timestamp NULL DEFAULT NULL,
`last-try` timestamp NULL DEFAULT NULL,
`num-tries` int(11) NOT NULL DEFAULT 0,
`data` mediumblob NULL DEFAULT NULL,
`http-code` smallint(1) unsigned NULL DEFAULT NULL,
`redirect-url` varchar(800) CHARACTER SET ascii COLLATE ascii_bin NULL DEFAULT NULL,
`redirect-url` varbinary(800) NOT NULL,
KEY `url` (`url`),
KEY `completed` (`completed`),
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_bin
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

View file

@ -32,7 +32,19 @@ function retriever_install() {
Addon::registerHook('contact_photo_menu', 'addon/retriever/retriever.php', 'retriever_contact_photo_menu');
Addon::registerHook('cron', 'addon/retriever/retriever.php', 'retriever_cron');
if (DI::config()->get('retriever', 'dbversion') != '0.14') {
if (DI::config()->get('retriever', 'dbversion') == '0.14') {
if (!DBA::e("ALTER TABLE `retriever_rule` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") ||
!DBA::e("ALTER TABLE `retriever_item` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") ||
!DBA::e("ALTER TABLE `retriever_item` MODIFY `item-uri` varbinary(255) NOT NULL") ||
!DBA::e("ALTER TABLE `retriever_resource` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") ||
!DBA::e("ALTER TABLE `retriever_resource` MODIFY `url` varbinary(800) NOT NULL") ||
!DBA::e("ALTER TABLE `retriever_resource` MODIFY `redirect-url` varbinary(800) NOT NULL")) {
Logger::warning('Unable to update database tables: ' . DBA::errorMessage());
return;
}
DI::config()->set('retriever', 'dbversion', '0.15');
}
if (DI::config()->get('retriever', 'dbversion') != '0.15') {
$schema = file_get_contents(dirname(__file__).'/database.sql');
$tables = explode(';', $schema);
foreach ($tables as $table) {