Skip to content

Commit 96bc5f3

Browse files
committed
Add prospect migrations: name & drop phones
Add SQL migrations to modify the prospects table: add a nullable name column and populate it from first_name + last_name, and remove mobile_phone and other_phone columns. Include Python runner scripts that execute these migrations using app.utils.db.get_db_connection_direct. SQL uses IF NOT EXISTS / IF EXISTS to make the changes idempotent.
1 parent c68b4fe commit 96bc5f3

6 files changed

Lines changed: 52 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Migration: Add name column and populate with first_name + ' ' + last_name
2+
ALTER TABLE prospects ADD COLUMN IF NOT EXISTS name TEXT;
3+
UPDATE prospects SET name = CONCAT_WS(' ', first_name, last_name);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Migration: Remove mobile_phone column from prospects table
2+
ALTER TABLE prospects DROP COLUMN IF EXISTS mobile_phone;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Migration: Remove other_phone column from prospects table
2+
ALTER TABLE prospects DROP COLUMN IF EXISTS other_phone;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import sys
3+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
4+
from app.utils.db import get_db_connection_direct
5+
6+
if __name__ == "__main__":
7+
sql = """
8+
ALTER TABLE prospects ADD COLUMN IF NOT EXISTS name TEXT;
9+
UPDATE prospects SET name = CONCAT_WS(' ', first_name, last_name);
10+
"""
11+
conn = get_db_connection_direct()
12+
cur = conn.cursor()
13+
cur.execute(sql)
14+
conn.commit()
15+
cur.close()
16+
conn.close()
17+
print("Migration complete: name column added and populated in prospects table.")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import sys
3+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
4+
from app.utils.db import get_db_connection_direct
5+
6+
if __name__ == "__main__":
7+
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS mobile_phone;"
8+
conn = get_db_connection_direct()
9+
cur = conn.cursor()
10+
cur.execute(sql)
11+
conn.commit()
12+
cur.close()
13+
conn.close()
14+
print('Migration complete: mobile_phone column dropped from prospects table.')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import sys
3+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
4+
from app.utils.db import get_db_connection_direct
5+
6+
if __name__ == "__main__":
7+
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS other_phone;"
8+
conn = get_db_connection_direct()
9+
cur = conn.cursor()
10+
cur.execute(sql)
11+
conn.commit()
12+
cur.close()
13+
conn.close()
14+
print('Migration complete: other_phone column dropped from prospects table.')

0 commit comments

Comments
 (0)