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
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Python - FastAPI, Postgres, tsvector"""

# Current Version
__version__ = "2.1.9"
__version__ = "2.2.0"
42 changes: 42 additions & 0 deletions app/api/prospects/prospects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}
40 changes: 0 additions & 40 deletions app/api/prospects/sql/create_table.sql

This file was deleted.

31 changes: 31 additions & 0 deletions app/api/prospects/sql/print_create_prospects_table.py
Original file line number Diff line number Diff line change
@@ -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'))
Binary file added app/static/python copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading