set working-directory := "../../../.."

default:
    just -f src/matchbox/server/postgresql/justfile -l

# Bring the database up to the latest migration script (the head)
apply:
    uv run alembic --config "src/matchbox/server/postgresql/alembic.ini" upgrade head

# Check if migration-generate would produce a migration script without creating one
check:
    uv run alembic --config "src/matchbox/server/postgresql/alembic.ini" check

# Autogenerate a new migration (keep your descriptive message brief as it is appended to the filename)
generate descriptive-message:
    uv run alembic --config "src/matchbox/server/postgresql/alembic.ini" revision --autogenerate -m "{{descriptive-message}}"

# Reset the DB to the base state
reset:
    uv run alembic --config "src/matchbox/server/postgresql/alembic.ini" downgrade base

# Drop the DB schema and alembic version altogether
drop:
    source .env && \
    PGPASSWORD="$MB__SERVER__POSTGRES__PASSWORD" \
    psql -h localhost -p "$MB__SERVER__POSTGRES__PORT" \
    -U "$MB__SERVER__POSTGRES__USER" -d "$MB__SERVER__POSTGRES__DATABASE" -v ON_ERROR_STOP=1 \
    -c "DROP SCHEMA IF EXISTS mb CASCADE; DROP TABLE IF EXISTS alembic_version;"

