Skip to content

Commit 4c84c0c

Browse files
committed
Bump to 2.2.0; add prospects SQL generator
Update package version to 2.2.0. Remove the static create_table.sql for prospects and add a Python utility (print_create_prospects_table.py) that introspects information_schema to generate a CREATE TABLE statement dynamically. Also add a static image (app/static/python copy.png). This replaces the hardcoded SQL with a script-driven approach for keeping table DDL in sync with the database.
1 parent 96bc5f3 commit 4c84c0c

4 files changed

Lines changed: 32 additions & 41 deletions

File tree

app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Python - FastAPI, Postgres, tsvector"""
22

33
# Current Version
4-
__version__ = "2.1.9"
4+
__version__ = "2.2.0"

app/api/prospects/sql/create_table.sql

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
def get_create_table_sql(table_name):
7+
conn = get_db_connection_direct()
8+
cur = conn.cursor()
9+
cur.execute("""
10+
SELECT column_name, data_type, is_nullable, column_default
11+
FROM information_schema.columns
12+
WHERE table_name = %s
13+
ORDER BY ordinal_position;
14+
""", (table_name,))
15+
columns = cur.fetchall()
16+
cur.close()
17+
conn.close()
18+
19+
lines = []
20+
for name, dtype, nullable, default in columns:
21+
line = f' {name} {dtype.upper()}'
22+
if nullable == 'NO':
23+
line += ' NOT NULL'
24+
if default:
25+
line += f' DEFAULT {default}'
26+
lines.append(line)
27+
create_sql = f"CREATE TABLE {table_name} (\n" + ",\n".join(lines) + "\n);"
28+
return create_sql
29+
30+
if __name__ == "__main__":
31+
print(get_create_table_sql('prospects'))

app/static/python copy.png

333 KB
Loading

0 commit comments

Comments
 (0)