fix: enable real utf-8 for mysql database

source: https://mathiasbynens.be/notes/mysql-utf8mb4
This commit is contained in:
Tobi Schäfer 2016-07-10 18:23:27 +02:00
parent f27a4cf5ac
commit 313833ecce
3 changed files with 177 additions and 71 deletions

View file

@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
antville.url = jdbc:mysql://localhost/antville?useUnicode=true&characterEncoding=utf8 antville.url = jdbc:mysql://localhost/antville?useUnicode=true
antville.driver = com.mysql.jdbc.Driver antville.driver = com.mysql.jdbc.Driver
antville.user = antville antville.user = antville
antville.password = antville antville.password = antville

134
db/my.sql
View file

@ -15,8 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
create database if not exists antville character set latin1 create database if not exists antville character set utf8mb4
collate latin1_general_ci; collate utf8mb4_unicode_ci;
use antville; use antville;
@ -27,15 +27,14 @@ set foreign_key_checks = 0;
create table account ( create table account (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
metadata mediumtext, email varchar(500),
email varchar(255) character set utf8 collate utf8_general_ci, status varchar(50),
status varchar(20),
created datetime, created datetime,
modified datetime, modified datetime,
primary key (id), primary key (id),
key name (name(20)), key name (name(191)),
key email (email(20)), key email (email(191)),
key status (status), key status (status),
key created (created), key created (created),
key modified (modified) key modified (modified)
@ -44,7 +43,7 @@ create table account (
create table choice ( create table choice (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
poll_id int(10) unsigned, poll_id int(10) unsigned,
title text character set utf8 collate utf8_general_ci, title text,
created datetime, created datetime,
modified datetime, modified datetime,
primary key (id), primary key (id),
@ -53,101 +52,97 @@ create table choice (
create table content ( create table content (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
prototype varchar(20), prototype varchar(50),
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
site_id int(10) unsigned, site_id int(10) unsigned,
story_id int(10) unsigned, story_id int(10) unsigned,
parent_id int(10) unsigned, parent_id int(10) unsigned,
parent_type varchar(20), parent_type varchar(50),
metadata mediumtext, status varchar(50),
status varchar(20), mode varchar(50),
mode varchar(20), comment_mode varchar(50),
comment_mode varchar(20),
requests int(10) unsigned, requests int(10) unsigned,
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key story_id (story_id), key story_id (story_id),
key parent_id (parent_id), key parent_id (parent_id),
key creator_id (creator_id), key creator_id (creator_id),
key type (site_id,prototype,status,created,modified,id), key type (site_id, prototype, status, created, modified, id),
key modified (site_id,modified,status,prototype,id) key modified (site_id, modified, status, prototype,id)
); );
create table file ( create table file (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
prototype varchar(20), prototype varchar(50),
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
site_id int(10) unsigned, site_id int(10) unsigned,
parent_id int(10) unsigned, parent_id int(10) unsigned,
parent_type varchar(20), parent_type varchar(50),
metadata mediumtext,
requests int(10) unsigned, requests int(10) unsigned,
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key site_id (site_id), key site_id (site_id),
key name (name(20)), key name (name(191)),
key creator_id (creator_id) key creator_id (creator_id)
); );
create table image ( create table image (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
prototype varchar(20), prototype varchar(50),
parent_id int(10) unsigned, parent_id int(10) unsigned,
parent_type varchar(20), parent_type varchar(50),
metadata mediumtext,
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key creator_id (creator_id), key creator_id (creator_id),
key type (name,prototype) key type (name(191), prototype)
); );
create table layout ( create table layout (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
site_id int(10) unsigned, site_id int(10) unsigned,
metadata mediumtext, mode varchar(50),
mode varchar(20),
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key site_id (site_id) key site_id (site_id)
); );
create table log ( create table log (
id int(10) unsigned not null auto_increment, id int(10) unsigned not null auto_increment,
context_id int(10) unsigned, context_id int(10) unsigned,
context_type varchar(20), context_type varchar(50),
referrer text, referrer text,
action varchar(255) character set utf8 collate utf8_general_ci, action varchar(500),
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
primary key (id) primary key (id)
); );
create table membership ( create table membership (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
site_id int(10) unsigned, site_id int(10) unsigned,
role varchar(20), role varchar(50),
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key site_id (site_id), key site_id (site_id),
key creator_id (creator_id), key creator_id (creator_id),
key name (name(20)) key name (name(191))
); );
#!helma <% #metadata %> #!helma <% #metadata %>
@ -155,14 +150,14 @@ create table membership (
create table metadata ( create table metadata (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
parent_id int(10) unsigned, parent_id int(10) unsigned,
parent_type varchar(20), parent_type varchar(50),
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
value mediumtext character set utf8 collate utf8_general_ci, value mediumtext,
type varchar(255), type varchar(500),
primary key (id), primary key (id),
key parent (parent_type, parent_id), key parent (parent_type, parent_id),
key name (name), key name (name(191)),
key value (value(255)) key value (value(191))
); );
#!helma <% #end_of_metadata %> #!helma <% #end_of_metadata %>
@ -170,79 +165,78 @@ create table metadata (
create table poll ( create table poll (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
site_id int(10) unsigned, site_id int(10) unsigned,
question text character set utf8 collate utf8_general_ci, question text,
status varchar(20), status varchar(50),
closed datetime, closed datetime,
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key site_id (site_id), key site_id (site_id),
key creator_id (creator_id) key creator_id (creator_id)
); );
create table site ( create table site (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
layout_id int(10) unsigned, layout_id int(10) unsigned,
metadata mediumtext, status varchar(50),
status varchar(20), mode varchar(50),
mode varchar(20),
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key name (name(20)), key name (name(191)),
key creator_id (creator_id) key creator_id (creator_id)
); );
create table skin ( create table skin (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
prototype varchar(30), prototype varchar(50),
source mediumtext, source mediumtext,
layout_id int(10) unsigned, layout_id int(10) unsigned,
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
modifier_id int(10) unsigned, modifier_id int(10) unsigned,
primary key (id), primary key (id),
key type (layout_id,prototype(10),name(10)) key type (layout_id, prototype, name(191))
); );
create table tag ( create table tag (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
name varchar(255) character set utf8 collate utf8_general_ci, name varchar(500),
site_id int(10) unsigned, site_id int(10) unsigned,
type varchar(20), type varchar(50),
primary key (id), primary key (id),
key tags (site_id,type,name) key tags (site_id, type, name(191))
); );
create table tag_hub ( create table tag_hub (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
tag_id int(10) unsigned, tag_id int(10) unsigned,
tagged_id int(10) unsigned, tagged_id int(10) unsigned,
tagged_type varchar(20), tagged_type varchar(50),
primary key (id), primary key (id),
key tagged (tag_id,tagged_type,tagged_id) key tagged (tag_id, tagged_type, tagged_id)
); );
create table vote ( create table vote (
id int(10) unsigned not null default '0', id int(10) unsigned not null default '0',
poll_id int(10) unsigned, poll_id int(10) unsigned,
choice_id int(10) unsigned, choice_id int(10) unsigned,
creator_name varchar(255) character set utf8 collate utf8_general_ci, creator_name varchar(500),
created datetime, created datetime,
creator_id int(10) unsigned, creator_id int(10) unsigned,
modified datetime, modified datetime,
primary key (id), primary key (id),
key poll_id (poll_id), key poll_id (poll_id),
key creator_id (creator_id), key creator_id (creator_id),
key choice_id (choice_id), key choice_id (choice_id),
key creator_name (creator_name(20)) key creator_name (creator_name(191))
); );
set foreign_key_checks = 1; set foreign_key_checks = 1;

View file

@ -0,0 +1,112 @@
// The Antville Project
// http://code.google.com/p/antville
//
// Copyright 20012016 by the Workers of Antville.
//
// Licensed under the Apache License, Version 2.0 (the ``License'');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ``AS IS'' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Apply with enabled updater repository using `ant patch -Dpatch.id=20160709`
var sql = new Sql();
var template;
sql.execute('alter database antville character set utf8mb4 collate utf8mb4_unicode_ci;');
template = 'alter table $0 convert to character set utf8mb4 collate utf8mb4_unicode_ci';
sql.execute(template, 'account');
sql.execute(template, 'choice');
sql.execute(template, 'content');
sql.execute(template, 'file');
sql.execute(template, 'image');
sql.execute(template, 'layout');
sql.execute(template, 'log');
sql.execute(template, 'membership');
sql.execute(template, 'metadata');
sql.execute(template, 'poll');
sql.execute(template, 'site');
sql.execute(template, 'skin');
sql.execute(template, 'tag');
sql.execute(template, 'tag_hub');
sql.execute(template, 'vote');
template = 'alter table $0 change $1 $1 $2 character set utf8mb4 collate utf8mb4_unicode_ci;'
sql.execute(template, 'account', 'name', 'varchar(500)');
sql.execute(template, 'account', 'email', 'varchar(500)');
sql.execute(template, 'account', 'status', 'varchar(50)');
sql.execute("alter table account drop key name;");
sql.execute("alter table account add key name (name(191));");
sql.execute("alter table account drop key email;");
sql.execute("alter table account add key email (email(191));");
sql.execute(template, 'choice', 'title', 'text');
sql.execute(template, 'content', 'prototype', 'varchar(50)');
sql.execute(template, 'content', 'name', 'name', 'varchar(500)');
sql.execute(template, 'content', 'parent_type', 'varchar(50)');
sql.execute(template, 'content', 'status', 'varchar(50)');
sql.execute(template, 'content', 'mode', 'varchar(50)');
sql.execute(template, 'content', 'comment_mode', 'varchar(50)');
sql.execute(template, 'file', 'prototype', 'varchar(50)');
sql.execute(template, 'file', 'name', 'varchar(500)');
sql.execute(template, 'file', 'parent_type', 'varchar(50)');
sql.execute("alter table file drop key name;");
sql.execute("alter table file add key name (name(191));");
sql.execute(template, 'image', 'name', 'varchar(500)');
sql.execute(template, 'image', 'prototype', 'varchar(50)');
sql.execute(template, 'image', 'parent_type', 'varchar(50)');
sql.execute("alter table image drop key type;");
sql.execute("alter table image add key type (name(191), prototype);");
sql.execute(template, 'layout', 'mode', 'varchar(50)');
sql.execute(template, 'log', 'context_type', 'varchar(50)');
sql.execute(template, 'log', 'action', 'varchar(500)');
sql.execute(template, 'membership', 'name', 'varchar(500)');
sql.execute(template, 'membership', 'role', 'varchar(50)');
sql.execute("alter table membership drop key name;");
sql.execute("alter table membership add key name (name(191));");
sql.execute(template, 'metadata', 'parent_type', 'varchar(50)');
sql.execute(template, 'metadata', 'name', 'varchar(500)');
sql.execute(template, 'metadata', 'value', 'mediumtext');
sql.execute("alter table metadata drop key name;");
sql.execute("alter table metadata add key name (name(191));");
sql.execute("alter table metadata drop key value;");
sql.execute("alter table metadata add key value (value(191));");
sql.execute(template, 'poll', 'question', 'text');
sql.execute(template, 'poll', 'status', 'varchar(50)');
sql.execute(template, 'site', 'name', 'varchar(500)');
sql.execute(template, 'site', 'status', 'varchar(50)');
sql.execute(template, 'site', 'mode', 'varchar(50)');
sql.execute("alter table site drop key name;");
sql.execute("alter table site add key name (name(191));");
sql.execute(template, 'skin', 'name', 'varchar(500)');
sql.execute(template, 'skin', 'prototype', 'varchar(50)');
sql.execute("alter table skin drop key type;");
sql.execute("alter table skin add key type (layout_id, prototype, name(191));");
sql.execute(template, 'tag', 'name', 'varchar(500)');
sql.execute(template, 'tag', 'type', 'varchar(50)');
sql.execute(template, 'tag_hub', 'tagged_type', 'varchar(50)');
sql.execute(template, 'vote', 'creator_name', 'varchar(500)');
sql.execute("alter table vote drop key creator_name;");
sql.execute("alter table vote add key creator_name (creator_name(191));");