Files
foxhunt/migrations/renumber_migrations.py
jgrusewski 0d9f890aa6 🗄️ Wave 112: Migration cleanup and new schemas
- Deprecated/broken migration files archived
- New auth_schema migration (015)
- Trading service events migration (016)
- Migration renumbering utility
- Migration test suite
2025-10-05 22:23:37 +02:00

34 lines
912 B
Python

#!/usr/bin/env python3
"""Renumber migration files to avoid conflicts."""
import os
import re
from pathlib import Path
# Get migrations directory
migrations_dir = Path(__file__).parent
# Find all _up_ and _down_ migration files
pattern = re.compile(r'^(\d{3})_(up_|down_)(.+\.sql)$')
renames = []
for filename in sorted(migrations_dir.glob('*.sql')):
match = pattern.match(filename.name)
if match:
old_version = int(match.group(1))
prefix = match.group(2)
suffix = match.group(3)
# Add 100 to version
new_version = old_version + 100
new_name = f"{new_version:03d}_{prefix}{suffix}"
renames.append((filename, migrations_dir / new_name))
# Execute renames
for old_path, new_path in renames:
print(f"✅ Renaming: {old_path.name} -> {new_path.name}")
old_path.rename(new_path)
print(f"\n✅ Renumbered {len(renames)} migration files")