Holy db migrations batman
This commit is contained in:
28
reset_db.sh
Executable file
28
reset_db.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# Recreate the database: run DROP and CREATE in separate psql calls (DROP DATABASE cannot run inside a transaction block)
|
||||
if ! docker exec -i meta_timescaledb psql -U meta_user -d postgres -c "DROP DATABASE IF EXISTS meta_insights;"; then
|
||||
echo "Error: failed to drop database 'meta_insights'." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker exec -i meta_timescaledb psql -U meta_user -d postgres -c "CREATE DATABASE meta_insights;"; then
|
||||
echo "Error: failed to create database 'meta_insights'." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# then import dump specified by argument only if previous commands succeeded
|
||||
if [ -n "$1" ]; then
|
||||
DUMP_FILE="$1"
|
||||
if [ ! -r "$DUMP_FILE" ]; then
|
||||
echo "Error: dump file '$DUMP_FILE' does not exist or is not readable." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "Importing dump from $DUMP_FILE"
|
||||
if ! docker exec -i meta_timescaledb psql -U meta_user -d meta_insights < "$DUMP_FILE"; then
|
||||
echo "Error: failed to import dump '$DUMP_FILE' into 'meta_insights'." >&2
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user