File size: 1,570 Bytes
580a4eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
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

# Add parent directory to 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()