Skip to main content
Repoch uses Alembic for database schema migrations. This guide covers how to apply migrations and create new ones.

Applying Migrations

After pulling changes that include new migrations, upgrade your database:
repoch alembic upgrade head
This uses your default database settings. If your database is not in the default location, or you are using a non-default configuration, pass the relevant options:
# Load a saved server config file
repoch alembic --config /path/to/config.toml upgrade head

# Load the cached server config (set via `repoch server --save`)
repoch alembic --cache upgrade head

# Override via environment variable
REPOCH__DATABASE__SQLITE_DIR=/path/to/data repoch alembic upgrade head

Creating Migrations

When you modify the database schema, generate a new migration:
repoch alembic revision --autogenerate -m "descriptive message here"
Review the generated migration file in versions/ before applying it.

Git Hook for Migration Alerts

Add this to your .git/hooks/post-merge file to receive alerts when new migrations are pulled:
# Alembic migrations check
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m'

MIGRATION_DIR="repoch/apps/api_server/database/alembic/versions"

if git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD | grep -q "^${MIGRATION_DIR}/"; then
    echo ""
    echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
    echo -e "${YELLOW}⚠️  NEW ALEMBIC MIGRATIONS DETECTED${NC}"
    echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
    echo ""
    echo "Run: ${GREEN}repoch alembic upgrade head${NC}"
    echo ""
fi

Next Steps

Adding Robot Middleware

Add support for new robot hardware