-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdbreset.sh
More file actions
executable file
·25 lines (20 loc) · 871 Bytes
/
Copy pathdbreset.sh
File metadata and controls
executable file
·25 lines (20 loc) · 871 Bytes
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
#!/bin/bash
# Drop and recreate the configured database, then load a dump into it.
# Uses the dump given as the first argument, or $DBDUMP otherwise.
# ./dbreset.sh # -> reload from $DBDUMP
# ./dbreset.sh snapshot.sql # -> reload from snapshot.sql
set -euo pipefail
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$DIR/_init.sh"
dump="${1:-$DBDUMP}"
if [ ! -f "$dump" ]; then
echo "$dump doesn't exist, falling back to ${DBDUMP}" >&2
dump="$DBDUMP"
fi
[ -f "$dump" ] || { echo "${dump} doesn't exist, exiting" >&2; exit 2; }
echo "Dropping database ${DBNAME} ..."
printf 'DROP DATABASE IF EXISTS `%s`;\n' "$DBNAME" | db_exec notty "$MYSQL_CMD"
echo "Creating database ${DBNAME} ..."
printf 'CREATE DATABASE IF NOT EXISTS `%s` CHARACTER SET utf8mb4;\n' "$DBNAME" \
| db_exec notty "$MYSQL_CMD"
"$DIR/dbpatch.sh" "$dump"