summaryrefslogtreecommitdiff
path: root/salt/openbook/database/files/update-openbook-schema.sh
blob: 93e3959ae32337a57d638e0ed77654e62ea772e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

pushd /root/update-openbook-schema >/dev/null

rm -rf openbook-v4-ci
git clone git@github.com:Talligent/openbook-v4-ci.git

pushd openbook-v4-ci/salt/openbook/database/files >/dev/null

mysqldump --skip-add-drop-table --skip-comments --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset --no-data --single-transaction -h 127.0.0.1 --databases openbook openbook_jobs openbook_workflow > create_openbook_schemas.sql

for db in openbook openbook_jobs openbook_workflow; do
    sed -e "s|USE \`${db}\`;|GRANT ALL PRIVILEGES ON ${db}.* TO ${db}@'%' IDENTIFIED BY '{% raw %}{{ openbook_database_password }}{% endraw %}';\nGRANT ALL PRIVILEGES ON ${db}.* TO ${db}@localhost IDENTIFIED BY '{% raw %}{{ openbook_database_password }}{% endraw %}';\n\nUSE \`${db}\`;|g" -i create_openbook_schemas.sql
done

sed --posix -r 's|(^.*PARTITION BY RANGE.*\))|\1;|g' -i create_openbook_schemas.sql
sed --posix -r 's|^.*PARTITION.*VALUES.*ENGINE = InnoDB.*$||g' -i create_openbook_schemas.sql
sed '/^$/d' -i create_openbook_schemas.sql

cat <<EOF >>create_openbook_schemas.sql
use openbook;
CALL p_preallocate_partitions('t_metric_values', 'metric_datetime', CURDATE(), 31);
CALL p_preallocate_partitions('t_metric_aggregate_resource_hourly', 'aggregate_datetime', CURDATE(), 31);
CALL p_preallocate_partitions('t_metric_aggregate_tenant_hourly', 'aggregate_datetime', CURDATE(), 31);
CALL p_preallocate_partitions('t_metric_aggregate_customer_hourly', 'aggregate_datetime', CURDATE(), 31);
CALL p_preallocate_partitions('t_metric_aggregate_resource_daily', 'aggregate_datetime', CURDATE(), 31);
CALL p_preallocate_partitions('t_metric_aggregate_tenant_daily', 'aggregate_datetime', CURDATE(), 31);
CALL p_preallocate_partitions('t_metric_aggregate_customer_daily', 'aggregate_datetime', CURDATE(), 31);
EOF

git add -A
git commit -a -m "update create_databases_schama.sql $(date)"
git push

popd >/dev/null
popd >/dev/null

exit 0