58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
import asyncio
|
|
|
|
from sqlalchemy import text
|
|
|
|
import db_setup
|
|
from job.job_post.models import JobPostStatusHistory, JobPosts
|
|
|
|
print("JobPosts.schema", JobPosts.__table__.schema)
|
|
print("History.schema", JobPostStatusHistory.__table__.schema)
|
|
print("metadata.schema", JobPosts.__table__.metadata.schema)
|
|
for fk in JobPostStatusHistory.__table__.foreign_keys:
|
|
print("FK", fk.target_fullname, "schema", fk.column.table.schema)
|
|
|
|
|
|
async def main():
|
|
async with db_setup.get_engine().begin() as conn:
|
|
rows = (
|
|
await conn.execute(
|
|
text(
|
|
"SELECT n.nspname AS schema, c.relname AS table "
|
|
"FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace "
|
|
"WHERE c.relname IN ('job_posts', 'job_post_status_history') "
|
|
"ORDER BY 1, 2"
|
|
)
|
|
)
|
|
).all()
|
|
print("TABLES", rows)
|
|
fks = (
|
|
await conn.execute(
|
|
text(
|
|
"SELECT con.conname, nsp.nspname AS src_schema, rel.relname AS src_table, "
|
|
"fnsp.nspname AS dst_schema, frel.relname AS dst_table, "
|
|
"pg_get_constraintdef(con.oid) AS def "
|
|
"FROM pg_constraint con "
|
|
"JOIN pg_class rel ON rel.oid = con.conrelid "
|
|
"JOIN pg_namespace nsp ON nsp.oid = rel.relnamespace "
|
|
"JOIN pg_class frel ON frel.oid = con.confrelid "
|
|
"JOIN pg_namespace fnsp ON fnsp.oid = frel.relnamespace "
|
|
"WHERE rel.relname = 'job_post_status_history'"
|
|
)
|
|
)
|
|
).all()
|
|
print("FKS")
|
|
for r in fks:
|
|
print(" ", dict(r._mapping))
|
|
print("search_path", (await conn.execute(text("SHOW search_path"))).scalar())
|
|
print("app.job_posts", (await conn.execute(text("SELECT count(*) FROM app.job_posts"))).scalar())
|
|
try:
|
|
print(
|
|
"public.job_posts",
|
|
(await conn.execute(text("SELECT count(*) FROM public.job_posts"))).scalar(),
|
|
)
|
|
except Exception as e:
|
|
print("public.job_posts ERR", type(e).__name__, e)
|
|
|
|
|
|
asyncio.run(main())
|