Final project commit: MTGJSON data integration and backend API
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""Inspect the actual database schema from the running containers."""
|
||||
import psycopg2
|
||||
import json
|
||||
|
||||
def inspect():
|
||||
conn = psycopg2.connect(
|
||||
host="172.18.0.2", port=5432,
|
||||
dbname="mtgdata", user="mtgonline", password="mtgonline_pass"
|
||||
)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Get actual mtg_cards columns
|
||||
cur.execute("""
|
||||
SELECT column_name, data_type, column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'mtg_cards'
|
||||
ORDER BY ordinal_position
|
||||
""")
|
||||
cards_cols = cur.fetchall()
|
||||
print("=== mtg_cards columns ===")
|
||||
for row in cards_cols:
|
||||
print(f" {row[0]}: {row[1]} (default: {row[2]})")
|
||||
|
||||
# Get actual mtg_sets columns
|
||||
cur.execute("""
|
||||
SELECT column_name, data_type, column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'mtg_sets'
|
||||
ORDER BY ordinal_position
|
||||
""")
|
||||
sets_cols = cur.fetchall()
|
||||
print("\n=== mtg_sets columns ===")
|
||||
for row in sets_cols:
|
||||
print(f" {row[0]}: {row[1]} (default: {row[2]})")
|
||||
|
||||
# Check counts
|
||||
cur.execute("SELECT COUNT(*) FROM mtg_cards")
|
||||
print(f"\nmtg_cards count: {cur.fetchone()[0]}")
|
||||
cur.execute("SELECT COUNT(*) FROM mtg_sets")
|
||||
print(f"mtg_sets count: {cur.fetchone()[0]}")
|
||||
|
||||
# Sample card
|
||||
print("\n=== Sample card (first row) ===")
|
||||
cur.execute("SELECT * FROM mtg_cards LIMIT 1")
|
||||
col_names = [d[0] for d in cur.description]
|
||||
row = cur.fetchone()
|
||||
for c, v in zip(col_names, row):
|
||||
print(f" {c}: {v}")
|
||||
|
||||
# Sample set
|
||||
print("\n=== Sample set (first row) ===")
|
||||
cur.execute("SELECT * FROM mtg_sets LIMIT 1")
|
||||
col_names = [d[0] for d in cur.description]
|
||||
row = cur.fetchone()
|
||||
for c, v in zip(col_names, row):
|
||||
print(f" {c}: {v}")
|
||||
|
||||
# Distinct rarities
|
||||
cur.execute("SELECT DISTINCT rarity FROM mtg_cards ORDER BY rarity")
|
||||
print(f"\nDistinct rarities: {[r[0] for r in cur.fetchall()]}")
|
||||
|
||||
# Distinct layouts
|
||||
cur.execute("SELECT DISTINCT layout FROM mtg_cards ORDER BY layout")
|
||||
print(f"Distinct layouts: {[r[0] for r in cur.fetchall()]}")
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
inspect()
|
||||
Reference in New Issue
Block a user