Commit 33d3246a authored by Alain Takoudjou's avatar Alain Takoudjou

repman: Allow to create database slave with character sets and collate options

parent b30539a9
......@@ -18,7 +18,7 @@ md5sum = 9aeb37bd4590aa7fa746ef70d78cc0d0
[instance-repman.cfg]
_update_hash_filename_ = instance-repman.cfg.jinja2.in
md5sum = 287e446905a6905606f5e12ae38e533f
md5sum = 8e4fcaf0e76a1b8a799c671dd3ad2de9
[config-toml.in]
_update_hash_filename_ = templates/config.toml.in
......@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30
[template-mariadb.cfg]
_update_hash_filename_ = instance-mariadb.cfg.jinja2.in
md5sum = e9c62f54824d7c6b549a864f9f67d0af
md5sum = b1344ec1c0ccd4670a87cea18b0aed53
[template-my-cnf]
_update_hash_filename_ = templates/my.cnf.in
......@@ -42,7 +42,7 @@ md5sum = f3661b788099bb31d71ba6e7d36836d9
[template-mariadb-initial-setup]
_update_hash_filename_ = templates/mariadb_initial_setup.sql.in
md5sum = c300e9c2fb67a5d41fadc572f4c02216
md5sum = 96c151c376600a90fe2a44825f2de550
[template-publish-slave-information]
_update_hash_filename_ = publish-database-slave-parameters.cfg.in
......
......@@ -311,7 +311,7 @@ command = ${template-mysqld-need-start:rendered}
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = slave-db-remove
frequency = */20 * * * *
frequency = */5 * * * *
command = ${mysql-slave-db-cleanup:rendered}
[template-mysqld-need-start]
......
......@@ -18,6 +18,36 @@
"title": "Database Password",
"type": "string",
"default": ""
},
"db_charset": {
"description": "Database Character set information.",
"title": "Database Character set information",
"type": "string",
"enum": [
"latin1",
"latin2",
"latin5",
"latin7",
"ascii",
"latin5",
"utf8",
"utf8mb4",
"utf16",
"utf16le",
"utf32",
"binary",
"utf8_general_ci",
"utf8_unicode_ci",
"utf8_unicode_ci",
"utf8mb4_bin",
"utf8mb4_general_ci",
"utf8mb4_unicode_ci",
"latin1_general_ci",
"latin1_bin",
"ascii_general_ci",
"ascii_bin"
],
"default": ""
}
},
"title": "Input Parameters",
......
......@@ -66,7 +66,8 @@ mode = 755
'name': 'db_%s' % instance_dict['slave_reference'].replace('-', '_').lower(),
'user': instance_dict.get('db_user', 'user'),
'password': instance_dict.get('db_password'),
'slave_reference': instance_dict['slave_reference']
'slave_reference': instance_dict['slave_reference'],
'charset': instance_dict.get('db_charset', '')
} -%}
{{ slave_dict['name'] }} = {{ dumps(slave_dict) }}
{% do dabase_slave_list.append(slave_dict) -%}
......
......@@ -10,8 +10,24 @@ DROP FUNCTION IF EXISTS sphinx_snippets;
CREATE DATABASE IF NOT EXISTS `repman_slave_definition`;
{% macro database(name, user, password) -%}
CREATE DATABASE IF NOT EXISTS `{{ name }}`;
{% macro database(name, user, password, charset="") -%}
{% set charset_collate = "" -%}
{% set charset_dict = {'utf8_general_ci': 'utf8',
'utf8_unicode_ci': 'utf8',
'utf8mb4_bin': 'utf8mb4',
'utf8mb4_general_ci': 'utf8mb4',
'utf8mb4_unicode_ci': 'utf8mb4',
'latin1_general_ci': 'latin1',
'latin1_bin': 'latin1',
'ascii_general_ci': 'ascii',
'ascii_bin': 'ascii'} -%}
{% if charset %}
{% set charset_collate = "CHARACTER SET %s" % charset -%}
{% if charset_dict.get(charset) -%}
{% set charset_collate = "CHARACTER SET %s COLLATE %s" % (charset_dict[charset], charset) -%}
{% endif -%}
{% endif -%}
CREATE DATABASE IF NOT EXISTS `{{ name }}` {{ charset_collate }};
{% if user -%}
GRANT ALL PRIVILEGES ON `{{ name }}`.* TO `{{ user }}`@`%` IDENTIFIED BY '{{ password }}';
GRANT ALL PRIVILEGES ON `{{ name }}`.* TO `{{ user }}`@localhost IDENTIFIED BY '{{ password }}';
......@@ -20,5 +36,5 @@ GRANT ALL PRIVILEGES ON `{{ name }}`.* TO `{{ user }}`@'::' IDENTIFIED BY '{{ pa
{% endmacro -%}
{% for entry in parameter_dict['database-list'] -%}
{{ database(entry['name'], entry.get('user'), entry.get('password')) }}
{{ database(entry['name'], entry.get('user'), entry.get('password'), entry.get('charset')) }}
{% endfor -%}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment