MAX bot + n8n: webhook, нормализация, меню, доки, схемы БД
- register_max_webhook.py, fetch_schema.py - n8n-code-node-max-normalize.js (max_id, callback из callback.user, contact из vcf_info) - n8n-code-add-menu-buttons.js (меню с callback, request_contact, Главное меню) - docs: max-webhook, max-curl-http-request, max-api (форматы, кнопки, контакт), clpr vs sprf - README, SITUATION, схемы sprf_ и clpr_, .gitignore Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
57
fetch_schema.py
Normal file
57
fetch_schema.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Выгрузка структуры таблиц sprf_ из PostgreSQL."""
|
||||
import os
|
||||
import psycopg2
|
||||
from pathlib import Path
|
||||
|
||||
# Загрузка .env
|
||||
env_path = Path(__file__).parent / ".env"
|
||||
for line in env_path.read_text().splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
if "=" in line:
|
||||
k, v = line.split("=", 1)
|
||||
os.environ[k.strip()] = v.strip()
|
||||
|
||||
conn = psycopg2.connect(
|
||||
host=os.environ["PGHOST"],
|
||||
port=int(os.environ.get("PGPORT", 5432)),
|
||||
dbname=os.environ["PGDATABASE"],
|
||||
user=os.environ["PGUSER"],
|
||||
password=os.environ["PGPASSWORD"],
|
||||
)
|
||||
cur = conn.cursor()
|
||||
cur.execute("""
|
||||
SELECT table_name, column_name, data_type,
|
||||
character_maximum_length, is_nullable, column_default, ordinal_position
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name LIKE 'sprf_%%'
|
||||
ORDER BY table_name, ordinal_position
|
||||
""")
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
# Группировка по таблицам
|
||||
from collections import defaultdict
|
||||
by_table = defaultdict(list)
|
||||
for table_name, col_name, data_type, char_max, nullable, default, ord_pos in rows:
|
||||
by_table[table_name].append((col_name, data_type, char_max, nullable, default))
|
||||
|
||||
# Вывод в файл
|
||||
out_path = Path(__file__).parent / "sprf_tables_schema.md"
|
||||
lines = ["# Структура таблиц sprf_ (public, default_db)\n"]
|
||||
for table in sorted(by_table.keys()):
|
||||
lines.append(f"## {table}\n")
|
||||
lines.append("| Колонка | Тип | Размер | NULL | Default |\n")
|
||||
lines.append("|---------|-----|--------|------|--------|\n")
|
||||
for col_name, data_type, char_max, nullable, default in by_table[table]:
|
||||
size = str(char_max) if char_max else ""
|
||||
default_str = (default or "").strip()[:40]
|
||||
if len((default or "")) > 40:
|
||||
default_str += "..."
|
||||
lines.append(f"| {col_name} | {data_type} | {size} | {nullable} | {default_str} |\n")
|
||||
lines.append("\n")
|
||||
out_path.write_text("".join(lines), encoding="utf-8")
|
||||
print(f"Сохранено: {out_path}")
|
||||
Reference in New Issue
Block a user