This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
forked from DiamondLightSource/ispyb-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·53 lines (42 loc) · 1.71 KB
/
build.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# Script to create the database from the schema .sql files and identify any
# update .sql files that haven't been run. Also generate documentation from
# inline comments in the schema.
# Some code borrowed from Stefan Buck's gist file at:
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
# Author: Karl Levik
source bin/functions.sh
if [ -z "${DB}" ]
then
DB="ispyb_build"
fi
echo "Dropping + creating build database"
mysql --defaults-file=.my.cnf -e "DROP DATABASE IF EXISTS $DB; CREATE DATABASE $DB; SET GLOBAL log_bin_trust_function_creators=ON;"
if [[ $? -eq 0 ]]
then
mysql --defaults-file=.my.cnf -D $DB < schemas/ispyb/tables.sql
mysql --defaults-file=.my.cnf -D $DB < schemas/ispyb/lookups.sql
mysql --defaults-file=.my.cnf -D $DB < schemas/ispyb/data.sql
mysql --defaults-file=.my.cnf -D $DB < schemas/ispyb/routines.sql
mysql --defaults-file=.my.cnf -D $DB < grants/ispyb_acquisition.sql
mysql --defaults-file=.my.cnf -D $DB < grants/ispyb_processing.sql
mysql --defaults-file=.my.cnf -D $DB < grants/ispyb_web.sql
mysql --defaults-file=.my.cnf -D $DB < grants/ispyb_import.sql
arr=$(bin/missed_updates.sh)
if [ -n "$arr" ]; then
echo "Running schemas/ispyb/updates/*.sql files that haven't yet been run:"
for sql_file in ${arr[@]}; do
echo "$sql_file"
mysql --defaults-file=.my.cnf -D ${DB} < "schemas/ispyb/updates/${sql_file}"
done
else
echo "No new schemas/ispyb/updates/*.sql files."
fi
# Generate table and sproc documentation
if [ -d "bin" ] && [ -d "docs" ]; then
cd bin
./db_procs_to_rst.sh $DB > ../docs/list_of_procs.rst
./db_tables_to_rst.sh $DB > ../docs/list_of_tables_and_columns.rst
cd ..
fi
fi