#!/usr/bin/env bash # Runs on the preview VM, in ~/app, after every upload. Safe to run again. # This one is for a Python app with PostgreSQL; change it to fit yours. set -euo pipefail export PGOPTIONS=--client-min-messages=warning # PostgreSQL, the first time. A copy of the base VM has it already. if ! command -v psql >/dev/null; then sudo apt-get update -q sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q postgresql sudo -u postgres createuser --superuser "$USER" fi # The database: created and seeded once, migrated on every push. fresh=0 if createdb app 2>/dev/null; then fresh=1; fi psql -q -v ON_ERROR_STOP=1 -d app -f db/schema.sql if [ "$fresh" = 1 ]; then psql -q -v ON_ERROR_STOP=1 -d app -f db/seed.sql fi # Dependencies uv sync --frozen --quiet # The app, as a systemd service, so it comes back after a restart sudo tee /etc/systemd/system/app.service >/dev/null <