|
|
""" |
|
|
Migration 008: Add current_address field to drivers table |
|
|
This stores the address for driver locations (provided by user along with lat/lng) |
|
|
""" |
|
|
|
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent)) |
|
|
|
|
|
from database.connection import execute_write |
|
|
|
|
|
|
|
|
def up(): |
|
|
"""Add current_address column to drivers table""" |
|
|
|
|
|
migrations = [ |
|
|
""" |
|
|
ALTER TABLE drivers |
|
|
ADD COLUMN IF NOT EXISTS current_address TEXT; |
|
|
""", |
|
|
] |
|
|
|
|
|
print("Migration 008: Adding current_address column to drivers...") |
|
|
|
|
|
for i, sql in enumerate(migrations, 1): |
|
|
try: |
|
|
print(f" [{i}/{len(migrations)}] Executing: {sql.strip()[:60]}...") |
|
|
execute_write(sql) |
|
|
print(f" Success") |
|
|
except Exception as e: |
|
|
print(f" Warning: {e}") |
|
|
|
|
|
print("\nMigration 008 complete!") |
|
|
|
|
|
|
|
|
def down(): |
|
|
"""Remove current_address column from drivers table""" |
|
|
|
|
|
rollback_migrations = [ |
|
|
"ALTER TABLE drivers DROP COLUMN IF EXISTS current_address;", |
|
|
] |
|
|
|
|
|
print("Rolling back Migration 008...") |
|
|
|
|
|
for i, sql in enumerate(rollback_migrations, 1): |
|
|
try: |
|
|
print(f" [{i}/{len(rollback_migrations)}] {sql[:60]}...") |
|
|
execute_write(sql) |
|
|
print(f" Success") |
|
|
except Exception as e: |
|
|
print(f" Warning: {e}") |
|
|
|
|
|
print("\nRollback complete!") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
import sys |
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "down": |
|
|
down() |
|
|
else: |
|
|
up() |
|
|
|