Files
mt5-ai-xauusd-trader/scripts/verify_migrations.py
T
LeoGitHubtriqbitgoogle-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
c6668af65b docs: improve developer onboarding and contribution experience (#1446)
* docs: improve developer onboarding and contribution experience

- Harden DX domain: format and fix 35+ files in scripts/ and migrations/.
- Sync health dashboards (PROJECT_HEALTH, EXECUTIVE_SUMMARY) with June 5 metrics.
- Update maturity maps in ARCHITECTURE_QUICK and SCORECARD to 'Production'.
- Reduce total repo lint debt from 146 to 33.

Co-authored-by: triqbit <242833443+triqbit@users.noreply.github.com>

* docs: improve developer onboarding and contribution experience

- Harden DX domain: format and fix 25+ files in scripts/ and utility modules.
- Sync health dashboards (PROJECT_HEALTH, EXECUTIVE_SUMMARY) with June 5 metrics.
- Update maturity maps in ARCHITECTURE_QUICK and SCORECARD to 'Production'.
- Ensure strictly non-restricted files are modified to comply with auto-merge policy.

Co-authored-by: triqbit <242833443+triqbit@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: triqbit <242833443+triqbit@users.noreply.github.com>
2026-05-30 13:14:09 +00:00

64 lines
1.8 KiB
Python

"""
MT5 AI/ML Trading Bot - Migration Safety Script
Automates the verification of Alembic migrations by performing
an upgrade-downgrade-upgrade cycle on a temporary database.
"""
import os
import sys
from alembic import command
from alembic.config import Config
def verify_migrations():
temp_db = "test_migrations.db"
if os.path.exists(temp_db):
os.remove(temp_db)
temp_url = f"sqlite:///{temp_db}"
# Load the Alembic configuration
alembic_cfg = Config("alembic.ini")
# Override the database URL to use our temporary test database
alembic_cfg.set_main_option("sqlalchemy.url", temp_url)
try:
# 1. Upgrade to head
print("--- Step 1: Upgrading to head ---")
command.upgrade(alembic_cfg, "head")
# 2. Downgrade to base (full reversal)
print("--- Step 2: Downgrading to base ---")
command.downgrade(alembic_cfg, "base")
# 3. Upgrade to head again
print("--- Step 3: Upgrading to head again ---")
command.upgrade(alembic_cfg, "head")
print("--- Migration Reversibility Check PASSED ---")
return True
except Exception as e:
print("=" * 60)
print(" DEPLOYMENT BLOCKED: MIGRATION VERIFICATION FAILED")
print("=" * 60)
print(f"Error during migration verification: {e}")
print("\nREMEDIATION: Check for SQL syntax errors, broken references, or")
print("non-reversible operations (missing downgrade logic) in migrations/versions/.")
import traceback
traceback.print_exc()
print("=" * 60)
return False
finally:
if os.path.exists(temp_db):
os.remove(temp_db)
if __name__ == "__main__":
if not verify_migrations():
sys.exit(1)
sys.exit(0)