Files
headquarter/scripts/update_db_password.py
alex c2c983a01e fix(alembic): bridge ghost migration 2026_05_28_add_tool_definition_manifests
The production database was stamped with a migration that no longer exists
in the codebase (created on another branch, applied, then removed). This
adds a no-op bridge migration so Alembic can reconcile the DB state.

- Create bridge migration 2026_05_28_add_tool_definition_manifests (no-op)
- Re-chain terminal_sessions migration to depend on the bridge
- Fixes startup failure: Can't locate revision identified by ...
2026-05-28 14:45:15 +02:00

73 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Securely update the PostgreSQL password for the headquarter database user.
Usage:
python scripts/update_db_password.py
The script will prompt for the new password (no echo) and update it via the
running hq-postgres Docker container.
After running, remember to update your .env file:
POSTGRES_PASSWORD=<your-new-password>
"""
import getpass
import subprocess
import sys
def main() -> None:
# Prompt for new password securely (no echo to terminal)
new_password = getpass.getpass("Enter new password for 'headquarter' user: ")
if not new_password:
print("Error: password cannot be empty.", file=sys.stderr)
sys.exit(1)
confirm = getpass.getpass("Confirm new password: ")
if new_password != confirm:
print("Error: passwords do not match.", file=sys.stderr)
sys.exit(1)
# Use psql inside the running postgres container to avoid exposing
# the password in host shell history.
sql = f"ALTER ROLE headquarter WITH PASSWORD '{new_password}';"
try:
result = subprocess.run(
[
"docker",
"exec",
"-i",
"hq-postgres",
"psql",
"-U",
"headquarter",
"-d",
"headquarter",
"-c",
sql,
],
capture_output=True,
text=True,
check=True,
)
print(result.stdout.strip())
print("\n✅ Password updated successfully.")
print("\n⚠️ IMPORTANT: Update your .env file:")
print(f" POSTGRES_PASSWORD={new_password}")
print("\n⚠️ Then restart the application containers:")
print(" docker compose up -d")
except subprocess.CalledProcessError as exc:
print(f"Error: {exc.stderr or exc.stdout}", file=sys.stderr)
sys.exit(1)
except FileNotFoundError:
print(
"Error: 'docker' command not found. Is Docker installed and running?",
file=sys.stderr,
)
sys.exit(1)
if __name__ == "__main__":
main()