Spaces:
Running
Running
Download backend/apply_billing_migration.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_billing_migration.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/apply_billing_migration.py
-
curl -L -o apply_billing_migration.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_billing_migration.py
1.67 kB
| """ | |
| Apply billing fields migration | |
| """ | |
| import asyncio | |
| import os | |
| from pathlib import Path | |
| # Add parent directory to path | |
| import sys | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| from sqlalchemy import text | |
| from app.core.database import async_engine | |
| async def apply_billing_migration(): | |
| """Apply add_billing_fields.sql migration.""" | |
| print("=" * 80) | |
| print("π§ APPLYING MIGRATION: add_billing_fields") | |
| print("=" * 80) | |
| migration_file = Path(__file__).parent / "migrations" / "add_billing_fields.sql" | |
| if not migration_file.exists(): | |
| print(f"β Migration file not found: {migration_file}") | |
| return | |
| # Read SQL | |
| with open(migration_file, 'r', encoding='utf-8') as f: | |
| sql = f.read() | |
| # Execute | |
| async with async_engine.begin() as conn: | |
| print("\nπ Executing SQL migration...") | |
| await conn.execute(text(sql)) | |
| print("β Migration applied successfully!") | |
| # Verify | |
| async with async_engine.begin() as conn: | |
| result = await conn.execute(text(""" | |
| SELECT column_name, data_type | |
| FROM information_schema.columns | |
| WHERE table_name = 'tenants' | |
| AND column_name IN ('leads_this_month', 'overage_charges', 'last_billing_date', 'next_billing_date') | |
| ORDER BY column_name | |
| """)) | |
| print("\nβ Column verification:") | |
| for row in result: | |
| print(f" {row.column_name}: {row.data_type}") | |
| print("\n" + "=" * 80) | |
| print("β MIGRATION COMPLETE") | |
| print("=" * 80) | |
| if __name__ == "__main__": | |
| asyncio.run(apply_billing_migration()) | |