45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
"""
|
|
Database migration script to add tier column to projects table
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from sqlalchemy import text
|
|
from src.database.session import get_session
|
|
|
|
|
|
def main():
|
|
"""Add tier column to projects table"""
|
|
session = next(get_session())
|
|
|
|
try:
|
|
session.execute(
|
|
text("ALTER TABLE projects ADD COLUMN tier INTEGER NOT NULL DEFAULT 1")
|
|
)
|
|
|
|
session.execute(
|
|
text("CREATE INDEX ix_projects_tier ON projects (tier)")
|
|
)
|
|
|
|
session.commit()
|
|
print("Successfully added tier column to projects table")
|
|
|
|
except Exception as e:
|
|
session.rollback()
|
|
if "duplicate column name" in str(e).lower() or "already exists" in str(e).lower():
|
|
print("Tier column already exists")
|
|
else:
|
|
print(f"Error adding tier column: {e}")
|
|
raise
|
|
finally:
|
|
session.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|