Skip to content

Commit fab0b3b

Browse files
Merge pull request #75 from goldlabelapps/staging
Add script to keep 8 random prospects
2 parents 9fba188 + 1f04314 commit fab0b3b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
conn = get_db_connection_direct()
8+
cur = conn.cursor()
9+
10+
# Step 1: Select 8 random ids
11+
cur.execute("SELECT id FROM prospects ORDER BY RANDOM() LIMIT 8;")
12+
ids = [row[0] for row in cur.fetchall()]
13+
print(f"Keeping these 8 ids: {ids}")
14+
15+
# Step 2: Cascade delete llm records, then delete prospects
16+
if ids:
17+
format_strings = ','.join(['%s'] * len(ids))
18+
# First, delete llm records referencing prospects that will be deleted
19+
delete_llm_sql = f"DELETE FROM llm WHERE prospect_id NOT IN ({format_strings});"
20+
cur.execute(delete_llm_sql, ids)
21+
# Now delete the prospects
22+
delete_sql = f"DELETE FROM prospects WHERE id NOT IN ({format_strings});"
23+
cur.execute(delete_sql, ids)
24+
conn.commit()
25+
print(f"Deleted all prospects except ids: {ids}")
26+
else:
27+
print("No records found in prospects table.")
28+
29+
cur.close()
30+
conn.close()

0 commit comments

Comments
 (0)