refactor: Clean up migration script and improve readability by removing unnecessary imports and formatting
This commit is contained in:
@@ -9,15 +9,15 @@ Adds the following fields:
|
|||||||
- investor_members.linkedin (VARCHAR, nullable)
|
- investor_members.linkedin (VARCHAR, nullable)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Add parent directory to path to import app modules
|
# Add parent directory to path to import app modules
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||||
|
|
||||||
from sqlalchemy import create_engine, text
|
from sqlalchemy import text
|
||||||
from app.db.db import DATABASE_URL, engine
|
|
||||||
|
from app.db.db import engine
|
||||||
|
|
||||||
|
|
||||||
def check_column_exists(conn, table_name, column_name):
|
def check_column_exists(conn, table_name, column_name):
|
||||||
@@ -38,9 +38,15 @@ def upgrade():
|
|||||||
if check_column_exists(conn, "projects", "is_archived"):
|
if check_column_exists(conn, "projects", "is_archived"):
|
||||||
print(" ✓ Column 'is_archived' already exists. Skipping.")
|
print(" ✓ Column 'is_archived' already exists. Skipping.")
|
||||||
else:
|
else:
|
||||||
conn.execute(text("ALTER TABLE projects ADD COLUMN is_archived INTEGER DEFAULT 0 NOT NULL"))
|
conn.execute(
|
||||||
|
text(
|
||||||
|
"ALTER TABLE projects ADD COLUMN is_archived INTEGER DEFAULT 0 NOT NULL"
|
||||||
|
)
|
||||||
|
)
|
||||||
# Set default value for existing rows
|
# Set default value for existing rows
|
||||||
conn.execute(text("UPDATE projects SET is_archived = 0 WHERE is_archived IS NULL"))
|
conn.execute(
|
||||||
|
text("UPDATE projects SET is_archived = 0 WHERE is_archived IS NULL")
|
||||||
|
)
|
||||||
print(" ✓ Successfully added 'is_archived' column to projects table")
|
print(" ✓ Successfully added 'is_archived' column to projects table")
|
||||||
|
|
||||||
# 2. Add product_service to companies table
|
# 2. Add product_service to companies table
|
||||||
@@ -64,7 +70,9 @@ def upgrade():
|
|||||||
if check_column_exists(conn, "investor_members", "linkedin"):
|
if check_column_exists(conn, "investor_members", "linkedin"):
|
||||||
print(" ✓ Column 'linkedin' already exists. Skipping.")
|
print(" ✓ Column 'linkedin' already exists. Skipping.")
|
||||||
else:
|
else:
|
||||||
conn.execute(text("ALTER TABLE investor_members ADD COLUMN linkedin VARCHAR"))
|
conn.execute(
|
||||||
|
text("ALTER TABLE investor_members ADD COLUMN linkedin VARCHAR")
|
||||||
|
)
|
||||||
print(" ✓ Successfully added 'linkedin' column to investor_members table")
|
print(" ✓ Successfully added 'linkedin' column to investor_members table")
|
||||||
|
|
||||||
print("\n" + "=" * 60)
|
print("\n" + "=" * 60)
|
||||||
@@ -98,7 +106,7 @@ if __name__ == "__main__":
|
|||||||
choices=["upgrade", "downgrade"],
|
choices=["upgrade", "downgrade"],
|
||||||
default="upgrade",
|
default="upgrade",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help="Migration direction (default: upgrade)"
|
help="Migration direction (default: upgrade)",
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -107,4 +115,3 @@ if __name__ == "__main__":
|
|||||||
upgrade()
|
upgrade()
|
||||||
else:
|
else:
|
||||||
downgrade()
|
downgrade()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user