chore: Archive legacy docs and backup files, prepare for codebase cleanup v2.0
This commit is contained in:
61
archive/2026.02.18 Archive_old_mapps/_legacy_backup/inspect_db.py
Executable file
61
archive/2026.02.18 Archive_old_mapps/_legacy_backup/inspect_db.py
Executable file
@@ -0,0 +1,61 @@
|
||||
import asyncio
|
||||
import os
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy import text
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Cím beállítása
|
||||
raw_url = os.getenv("DATABASE_URL")
|
||||
if not raw_url:
|
||||
raw_url = "postgresql://admin:PASSWORD_111@postgres-db:5432/service_finder"
|
||||
DATABASE_URL = raw_url.replace("postgresql://", "postgresql+asyncpg://").replace("/service_finder_db", "/service_finder")
|
||||
|
||||
async def inspect_schema():
|
||||
print(f"🔎 Kapcsolódás az adatbázishoz...")
|
||||
engine = create_async_engine(DATABASE_URL)
|
||||
|
||||
async with engine.begin() as conn:
|
||||
# SQL lekérdezés a rendszer katalógusból (information_schema)
|
||||
# Ez megmondja milyen táblák és oszlopok léteznek
|
||||
query = text("""
|
||||
SELECT
|
||||
table_schema,
|
||||
table_name,
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema IN ('public', 'ref', 'data')
|
||||
ORDER BY table_schema, table_name, ordinal_position;
|
||||
""")
|
||||
|
||||
result = await conn.execute(query)
|
||||
rows = result.fetchall()
|
||||
|
||||
if not rows:
|
||||
print("⚠️ Nem találtam táblákat a 'ref' vagy 'data' sémákban!")
|
||||
|
||||
current_table = ""
|
||||
for row in rows:
|
||||
schema = row.table_schema
|
||||
table = row.table_name
|
||||
full_table_name = f"{schema}.{table}"
|
||||
|
||||
# Ha új táblához érünk, kiírjuk a nevét
|
||||
if full_table_name != current_table:
|
||||
print(f"\n📦 TÁBLA: {full_table_name.upper()}")
|
||||
print("-" * 50)
|
||||
print(f"{'OSZLOP NÉV':<20} | {'TÍPUS':<15} | {'KÖTELEZŐ?'}")
|
||||
print("-" * 50)
|
||||
current_table = full_table_name
|
||||
|
||||
# Oszlop adatok
|
||||
req = "IGEN" if row.is_nullable == 'NO' else "nem"
|
||||
print(f"{row.column_name:<20} | {row.data_type:<15} | {req}")
|
||||
|
||||
await engine.dispose()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(inspect_schema())
|
||||
Reference in New Issue
Block a user