"""
檢查所有 RBAC 相關表是否存在
"""
import psycopg2

conn = psycopg2.connect(
    host="10.1.0.20",
    port=5433,
    database="hr_portal",
    user="admin",
    password="DC1qaz2wsx"
)
cur = conn.cursor()

required_tables = [
    'tenant_user_roles',
    'tenant_role_rights',
    'tenant_user_role_assignments',
]

print("Checking required tables:\n")

for table in required_tables:
    cur.execute("""
        SELECT EXISTS (
            SELECT FROM information_schema.tables
            WHERE table_name = %s
        );
    """, (table,))
    exists = cur.fetchone()[0]
    status = "OK" if exists else "MISSING"
    print(f"  [{status}] {table}")

cur.close()
conn.close()
