fs-lawrisk/tests/verify_base_table.py

47 lines
1.5 KiB
Python
Raw Normal View History

import os
from lawrisk.services.licensing_repo import _lic_pg_conn
from lawrisk.utils.env_loader import load_env
def verify_table():
load_env()
with _lic_pg_conn() as conn:
cur = conn.cursor()
# 1. Check if permit_theme_rules table exists
cur.execute("""
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'permit_theme_rules'
);
""")
exists = cur.fetchone()[0]
print(f"Table 'permit_theme_rules' exists: {exists}")
if exists:
# 2. Check structure
cur.execute("""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'permit_theme_rules';
""")
columns = cur.fetchall()
print("Table structure:")
for col in columns:
print(f" - {col[0]} ({col[1]})")
# 3. Check sample data
cur.execute("SELECT count(*) FROM permit_theme_rules;")
count = cur.fetchone()[0]
print(f"Total rules in table: {count}")
if count > 0:
cur.execute("SELECT permit_name, theme_id FROM permit_theme_rules LIMIT 5;")
rules = cur.fetchall()
print("Sample rules:")
for rule in rules:
print(f" - Permit: {rule[0]}, Theme ID: {rule[1]}")
if __name__ == "__main__":
verify_table()