Skip to content

Commit 43be8f6

Browse files
Merge pull request #43 from goldlabelapps/staging
Add DB inspection and pg_trgm utility scripts
2 parents 21ed522 + 0aa31f5 commit 43be8f6

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Quick script to check if any prospects contain 'chris' in name, email, or company.
3+
"""
4+
def check_chris():
5+
6+
from app.utils.db import get_db_connection
7+
8+
def check_chris():
9+
conn_gen = get_db_connection()
10+
conn = next(conn_gen)
11+
cur = conn.cursor()
12+
try:
13+
cur.execute("""
14+
SELECT id, first_name, last_name, email, company_name FROM prospects
15+
WHERE (
16+
LOWER(first_name) LIKE '%chris%'
17+
OR LOWER(last_name) LIKE '%chris%'
18+
OR LOWER(email) LIKE '%chris%'
19+
OR LOWER(company_name) LIKE '%chris%'
20+
)
21+
AND hide IS NOT TRUE
22+
LIMIT 10;
23+
""")
24+
rows = cur.fetchall()
25+
if rows:
26+
for row in rows:
27+
print(row)
28+
else:
29+
print("No prospects found with 'chris' in first_name, last_name, email, or company_name.")
30+
except Exception as e:
31+
print(f"Error: {e}")
32+
finally:
33+
cur.close()
34+
conn.close()
35+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Check if pg_trgm extension is enabled in the PostgreSQL database.
3+
"""
4+
import psycopg2
5+
from app.utils.db import get_db_connection
6+
7+
def check_pg_trgm():
8+
conn_gen = get_db_connection()
9+
conn = next(conn_gen)
10+
cur = conn.cursor()
11+
try:
12+
cur.execute("SELECT extname FROM pg_extension WHERE extname = 'pg_trgm';")
13+
result = cur.fetchone()
14+
if result:
15+
print("pg_trgm extension is ENABLED.")
16+
else:
17+
print("pg_trgm extension is NOT enabled.")
18+
except Exception as e:
19+
print(f"Failed to check pg_trgm: {e}")
20+
finally:
21+
cur.close()
22+
conn.close()
23+
24+
if __name__ == "__main__":
25+
check_pg_trgm()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Migration script to enable pg_trgm extension for fuzzy search support.
3+
Run this script once to enable the extension in your PostgreSQL database.
4+
"""
5+
import psycopg2
6+
from app.utils.db import get_db_connection
7+
8+
def enable_pg_trgm():
9+
conn_gen = get_db_connection()
10+
conn = next(conn_gen)
11+
cur = conn.cursor()
12+
try:
13+
cur.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm;")
14+
conn.commit()
15+
print("pg_trgm extension enabled successfully.")
16+
except Exception as e:
17+
print(f"Failed to enable pg_trgm: {e}")
18+
finally:
19+
cur.close()
20+
conn.close()
21+
22+
if __name__ == "__main__":
23+
enable_pg_trgm()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Script to print the column names of the prospects table for debugging.
3+
"""
4+
from app.utils.db import get_db_connection
5+
6+
def print_prospects_columns():
7+
conn_gen = get_db_connection()
8+
conn = next(conn_gen)
9+
cur = conn.cursor()
10+
try:
11+
cur.execute("SELECT * FROM prospects LIMIT 1;")
12+
columns = [desc[0] for desc in cur.description]
13+
print("Columns in prospects table:", columns)
14+
except Exception as e:
15+
print(f"Error: {e}")
16+
finally:
17+
cur.close()
18+
conn.close()
19+
20+
if __name__ == "__main__":
21+
print_prospects_columns()

0 commit comments

Comments
 (0)