diff --git a/app/__init__.py b/app/__init__.py index 01b75b2..b41c612 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,4 +1,4 @@ """Python - FastAPI, Postgres, tsvector""" # Current Version -__version__ = "2.1.9" +__version__ = "2.2.0" diff --git a/app/api/prospects/prospects.py b/app/api/prospects/prospects.py index 10bb5ad..5b7d0c4 100644 --- a/app/api/prospects/prospects.py +++ b/app/api/prospects/prospects.py @@ -135,6 +135,26 @@ def prospects_read_one(id: int = Path(..., description="ID of the prospect to re return {"meta": meta, "data": data} +# PATCH endpoint to factory reset all prospects (ensure only one definition, at end of file) +@router.patch("/prospects/factoryreset") +def factory_reset_prospects() -> dict: + """Reset all prospects' flag and hide fields to False.""" + meta = make_meta("success", "Factory reset all prospects (flag, hide)") + conn_gen = get_db_connection() + conn = next(conn_gen) + cur = conn.cursor() + try: + cur.execute("UPDATE prospects SET flag = FALSE, hide = FALSE;") + conn.commit() + data = {"reset": True} + except Exception as e: + meta = make_meta("error", f"Failed to factory reset: {str(e)}") + data = {"reset": False} + finally: + cur.close() + conn.close() + return {"meta": meta, "data": data} + # PATCH endpoint to update flag/hide @router.patch("/prospects/{id}") def update_prospect(id: int = Path(..., description="ID of the prospect to update"), update: ProspectUpdate = Body(...)) -> dict: @@ -174,4 +194,26 @@ def update_prospect(id: int = Path(..., description="ID of the prospect to updat finally: cur.close() conn.close() + return {"meta": meta, "data": data} + + + +# PATCH endpoint to factory reset all prospects (ensure only one definition, at end of file) +@router.patch("/prospects/factoryreset") +def factory_reset_prospects() -> dict: + """Reset all prospects' flag and hide fields to False.""" + meta = make_meta("success", "Factory reset all prospects (flag, hide)") + conn_gen = get_db_connection() + conn = next(conn_gen) + cur = conn.cursor() + try: + cur.execute("UPDATE prospects SET flag = FALSE, hide = FALSE;") + conn.commit() + data = {"reset": True} + except Exception as e: + meta = make_meta("error", f"Failed to factory reset: {str(e)}") + data = {"reset": False} + finally: + cur.close() + conn.close() return {"meta": meta, "data": data} \ No newline at end of file diff --git a/app/api/prospects/sql/create_table.sql b/app/api/prospects/sql/create_table.sql deleted file mode 100644 index 086db07..0000000 --- a/app/api/prospects/sql/create_table.sql +++ /dev/null @@ -1,40 +0,0 @@ -CREATE TABLE IF NOT EXISTS prospects ( - id SERIAL PRIMARY KEY, - first_name TEXT, - last_name TEXT, - title TEXT, - company_name TEXT, - email TEXT, - email_status TEXT, - primary_email_source TEXT, - primary_email_verification_source TEXT, - email_confidence TEXT, - primary_email_catchall_status TEXT, - primary_email_last_verified_at TEXT, - seniority TEXT, - sub_departments TEXT, - work_direct_phone TEXT, - home_phone TEXT, - mobile_phone TEXT, - corporate_phone TEXT, - other_phone TEXT, - do_not_call TEXT, - lists TEXT, - person_linkedin_url TEXT, - country TEXT, - subsidiary_of TEXT, - subsidiary_of_organization_id TEXT, - tertiary_email TEXT, - tertiary_email_source TEXT, - tertiary_email_status TEXT, - tertiary_email_verification_source TEXT, - primary_intent_topic TEXT, - primary_intent_score TEXT, - secondary_intent_topic TEXT, - secondary_intent_score TEXT, - qualify_contact TEXT, - cleaned TEXT, - search_vector TSVECTOR, - flag BOOLEAN DEFAULT FALSE, - hide BOOLEAN DEFAULT FALSE -); diff --git a/app/api/prospects/sql/print_create_prospects_table.py b/app/api/prospects/sql/print_create_prospects_table.py new file mode 100644 index 0000000..88986ff --- /dev/null +++ b/app/api/prospects/sql/print_create_prospects_table.py @@ -0,0 +1,31 @@ +import os +import sys +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..'))) +from app.utils.db import get_db_connection_direct + +def get_create_table_sql(table_name): + conn = get_db_connection_direct() + cur = conn.cursor() + cur.execute(""" + SELECT column_name, data_type, is_nullable, column_default + FROM information_schema.columns + WHERE table_name = %s + ORDER BY ordinal_position; + """, (table_name,)) + columns = cur.fetchall() + cur.close() + conn.close() + + lines = [] + for name, dtype, nullable, default in columns: + line = f' {name} {dtype.upper()}' + if nullable == 'NO': + line += ' NOT NULL' + if default: + line += f' DEFAULT {default}' + lines.append(line) + create_sql = f"CREATE TABLE {table_name} (\n" + ",\n".join(lines) + "\n);" + return create_sql + +if __name__ == "__main__": + print(get_create_table_sql('prospects')) diff --git a/app/static/python copy.png b/app/static/python copy.png new file mode 100644 index 0000000..2581b81 Binary files /dev/null and b/app/static/python copy.png differ