ops: add DB restore and deploy script

This commit is contained in:
Apple
2025-11-30 14:05:55 -08:00
parent 1830109a95
commit 534bd72183

View File

@@ -0,0 +1,37 @@
#!/bin/bash
set -e
# 1. Pull latest code
echo "Pulling latest code..."
cd /opt/microdao-daarion
git pull origin main
# 2. Check if database exists, create if not
echo "Checking database..."
if docker exec dagi-postgres psql -U postgres -lqt | cut -d \| -f 1 | grep -qw daarion_memory; then
echo "Database daarion_memory exists."
else
echo "Database daarion_memory does not exist. Creating..."
docker exec dagi-postgres psql -U postgres -c "CREATE DATABASE daarion_memory;"
fi
# 3. Apply all migrations in order
echo "Applying migrations..."
for f in migrations/*.sql; do
echo "Applying $f..."
# Check if migration needed?
# For simplicity in this recovery script, we assume psql will handle "IF NOT EXISTS" errors
# or we just run them.
# Real production migration tools track versions.
# Here we rely on SQL idempotency or manual check.
# Most of our recent migrations use "CREATE TABLE IF NOT EXISTS".
# Let's run them.
docker exec -i dagi-postgres psql -U postgres -d daarion_memory < "$f"
done
# 4. Rebuild and restart city-service
echo "Restarting city-service..."
docker-compose up -d --build city-service
echo "Deployment and DB restoration complete!"