Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/api/prospects/database/check_chris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Quick script to check if any prospects contain 'chris' in name, email, or company.
"""
def check_chris():

from app.utils.db import get_db_connection

Comment on lines +4 to +7
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module currently has an empty def check_chris(): followed by a second def check_chris(): and a top-level import after the first function header. As written, this is a syntax/indentation error (function with no body) and the script will fail to run/import. Remove the stray first definition and move imports to the top so there is exactly one valid check_chris function definition.

Suggested change
def check_chris():
from app.utils.db import get_db_connection
from app.utils.db import get_db_connection

Copilot uses AI. Check for mistakes.
def check_chris():
conn_gen = get_db_connection()
conn = next(conn_gen)
Comment on lines +6 to +10
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other scripts: get_db_connection() is a generator with cleanup in its finally, but this script advances it with next() and never closes the generator. Prefer get_db_connection_direct() for this standalone script, or close the generator explicitly in finally to ensure the generator's cleanup path runs.

Suggested change
from app.utils.db import get_db_connection
def check_chris():
conn_gen = get_db_connection()
conn = next(conn_gen)
from app.utils.db import get_db_connection_direct
def check_chris():
conn = get_db_connection_direct()

Copilot uses AI. Check for mistakes.
cur = conn.cursor()
try:
cur.execute("""
SELECT id, first_name, last_name, email, company_name FROM prospects
WHERE (
LOWER(first_name) LIKE '%chris%'
OR LOWER(last_name) LIKE '%chris%'
OR LOWER(email) LIKE '%chris%'
OR LOWER(company_name) LIKE '%chris%'
)
AND hide IS NOT TRUE
LIMIT 10;
""")
rows = cur.fetchall()
if rows:
for row in rows:
print(row)
else:
print("No prospects found with 'chris' in first_name, last_name, email, or company_name.")
except Exception as e:
print(f"Error: {e}")
finally:
cur.close()
conn.close()

Comment on lines +31 to +35
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions these scripts include CLI entry points where appropriate, but this script doesn't currently have an if __name__ == "__main__": ... block to invoke check_chris(). Add a main guard at the bottom so it can be run directly like the other utility scripts.

Copilot uses AI. Check for mistakes.
25 changes: 25 additions & 0 deletions app/api/prospects/database/check_pg_trgm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Check if pg_trgm extension is enabled in the PostgreSQL database.
"""
import psycopg2
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psycopg2 is imported but not used anywhere in this script. Please remove the unused import to avoid lint errors and keep dependencies clear.

Suggested change
import psycopg2

Copilot uses AI. Check for mistakes.
from app.utils.db import get_db_connection

def check_pg_trgm():
conn_gen = get_db_connection()
conn = next(conn_gen)
Comment on lines +5 to +9
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_db_connection() is a generator intended for FastAPI dependency injection (it closes the connection in the generator's finally). Here the generator is advanced with next() but never closed, so that finally block will not run. Prefer get_db_connection_direct() for scripts, or explicitly close the generator (e.g., in finally) instead of only closing the connection.

Suggested change
from app.utils.db import get_db_connection
def check_pg_trgm():
conn_gen = get_db_connection()
conn = next(conn_gen)
from app.utils.db import get_db_connection_direct
def check_pg_trgm():
conn = get_db_connection_direct()

Copilot uses AI. Check for mistakes.
cur = conn.cursor()
try:
cur.execute("SELECT extname FROM pg_extension WHERE extname = 'pg_trgm';")
result = cur.fetchone()
if result:
print("pg_trgm extension is ENABLED.")
else:
print("pg_trgm extension is NOT enabled.")
except Exception as e:
print(f"Failed to check pg_trgm: {e}")
finally:
cur.close()
conn.close()

if __name__ == "__main__":
check_pg_trgm()
23 changes: 23 additions & 0 deletions app/api/prospects/database/enable_pg_trgm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Migration script to enable pg_trgm extension for fuzzy search support.
Run this script once to enable the extension in your PostgreSQL database.
"""
import psycopg2
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psycopg2 is imported but never used in this script. Removing the unused import avoids lint failures and reduces confusion about intended exception handling.

Suggested change
import psycopg2

Copilot uses AI. Check for mistakes.
from app.utils.db import get_db_connection

def enable_pg_trgm():
conn_gen = get_db_connection()
conn = next(conn_gen)
Comment on lines +6 to +10
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_db_connection() is a generator meant to be used as a FastAPI dependency; advancing it with next() without later closing the generator skips its finally cleanup path. For standalone scripts, prefer get_db_connection_direct(), or ensure the generator is properly closed in finally (rather than only calling conn.close()).

Suggested change
from app.utils.db import get_db_connection
def enable_pg_trgm():
conn_gen = get_db_connection()
conn = next(conn_gen)
from app.utils.db import get_db_connection, get_db_connection_direct
def enable_pg_trgm():
conn = get_db_connection_direct()

Copilot uses AI. Check for mistakes.
cur = conn.cursor()
try:
cur.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm;")
conn.commit()
print("pg_trgm extension enabled successfully.")
except Exception as e:
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On exception, the connection is left in a failed transaction state but never rolled back. Add conn.rollback() in the except block so the connection is cleanly reset before closing (and to match error-handling patterns used in other DB scripts/endpoints).

Suggested change
except Exception as e:
except Exception as e:
conn.rollback()

Copilot uses AI. Check for mistakes.
print(f"Failed to enable pg_trgm: {e}")
finally:
cur.close()
conn.close()

if __name__ == "__main__":
enable_pg_trgm()
21 changes: 21 additions & 0 deletions app/api/prospects/database/print_prospects_columns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Script to print the column names of the prospects table for debugging.
"""
from app.utils.db import get_db_connection

def print_prospects_columns():
conn_gen = get_db_connection()
conn = next(conn_gen)
cur = conn.cursor()
try:
cur.execute("SELECT * FROM prospects LIMIT 1;")
columns = [desc[0] for desc in cur.description]
print("Columns in prospects table:", columns)
except Exception as e:
print(f"Error: {e}")
finally:
cur.close()
conn.close()
Comment on lines +8 to +18
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_db_connection() is implemented as a generator (FastAPI dependency). This script calls next() on it but never closes the generator, so the generator's finally block is skipped. Use get_db_connection_direct() for one-off scripts, or close the generator in finally to ensure its cleanup logic always runs.

Suggested change
conn = next(conn_gen)
cur = conn.cursor()
try:
cur.execute("SELECT * FROM prospects LIMIT 1;")
columns = [desc[0] for desc in cur.description]
print("Columns in prospects table:", columns)
except Exception as e:
print(f"Error: {e}")
finally:
cur.close()
conn.close()
try:
conn = next(conn_gen)
cur = conn.cursor()
try:
cur.execute("SELECT * FROM prospects LIMIT 1;")
columns = [desc[0] for desc in cur.description]
print("Columns in prospects table:", columns)
except Exception as e:
print(f"Error: {e}")
finally:
cur.close()
conn.close()
finally:
conn_gen.close()

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +18
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the SELECT fails (e.g., missing table/permissions), psycopg2 leaves the session in an aborted transaction state. Consider calling conn.rollback() in the except block to keep error handling consistent with the other DB utility scripts in this directory.

Copilot uses AI. Check for mistakes.

if __name__ == "__main__":
print_prospects_columns()
Loading