apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-initdb-config
data:
  my.cnf: |-
    [client]
    port		= 3306
    socket		= /tmp/mysql.sock
    [mysqld]
    port		= 3306
    socket		= /tmp/mysql.sock
    skip-external-locking
    key_buffer_size = 16K
    max_allowed_packet = 1M
    table_open_cache = 4
    sort_buffer_size = 64K
    read_buffer_size = 256K
    read_rnd_buffer_size = 256K
    net_buffer_length = 2K
    thread_stack = 250K
    sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    server-id	= 1
    collation-server = utf8_bin
    init-connect='SET NAMES utf8'
    character-set-server = utf8
    [mysqldump]
    quick
    max_allowed_packet = 16M
    column-statistics = 0
    [mysql]
    no-auto-rehash
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    [mysqlhotcopy]
    interactive-timeout
  my.sh: |-
    #!/bin/sh
    mysql -u root -ppassword \
      --execute=" CREATE DATABASE IF NOT EXISTS ifs ; \
        CREATE DATABASE IF NOT EXISTS ifs_test; \
        CREATE DATABASE IF NOT EXISTS ifs_finance; \
        CREATE DATABASE IF NOT EXISTS ifs_finance_test; \
        CREATE DATABASE IF NOT EXISTS ifs_survey; \
        CREATE DATABASE IF NOT EXISTS ifs_survey_test;"
    if [ -f /tmp/anonymised-dump.sql ]; then
        mysql -u root -p ifs -ppassword < /tmp/anonymised-dump.sql
        mysql -u root -p ifs -ppassword \
          --execute="update user set uid='c0d02979-e66e-11e7-ac43-0242ac120002' where \
          email='ifs_web_user@innovateuk.org'"
        echo "imported dump successfully"
    fi
    echo "database is ready"
    exit

