-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.py
More file actions
39 lines (31 loc) · 1.43 KB
/
Copy pathcleanup.py
File metadata and controls
39 lines (31 loc) · 1.43 KB
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
import os
import psycopg2
def main():
dsn = "postgresql://dira:dira_password@localhost:5433/dira_db"
env_path = "./.env"
if os.path.exists(env_path):
with open(env_path, "r") as f:
for line in f:
if line.startswith("DATABASE_URL="):
dsn = line.split("=", 1)[1].strip().strip('"').strip("'")
break
print(f"Connecting to database: {dsn}")
conn = psycopg2.connect(dsn)
conn.autocommit = True
with conn.cursor() as cur:
# Delete existing vendors with the phone number '+254712345678'
cur.execute("DELETE FROM vendors WHERE phone_number = %s", ('+254712345678',))
deleted_vendors = cur.rowcount
print(f"Deleted {deleted_vendors} existing vendor records.")
# Delete existing auth_users with temporary email addresses
cur.execute("DELETE FROM auth_users WHERE email LIKE 'mama_%'")
deleted_users = cur.rowcount
print(f"Deleted {deleted_users} existing temporary auth_users records.")
# Clean up any residual supply gaps for the items we will test
cur.execute("DELETE FROM supply_gaps WHERE item_name IN ('Mango Juice', 'Maji Baridi')")
deleted_gaps = cur.rowcount
print(f"Deleted {deleted_gaps} residual supply gap records.")
conn.close()
print("Database cleanup completed successfully.")
if __name__ == "__main__":
main()