Holy db migrations batman

This commit is contained in:
Jonas Linter
2025-12-03 10:41:34 +01:00
parent 2c3d779ab2
commit 08f85d1b26
19 changed files with 752 additions and 84 deletions

28
reset_db.sh Executable file
View 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