34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import sys
|
|
import os
|
|
os.environ["CORE_DB_HOST"] = "localhost"
|
|
sys.path.append(os.path.join(os.getcwd(), 'backend'))
|
|
from core.database import get_core_db
|
|
from sqlalchemy import text
|
|
|
|
db = next(get_core_db())
|
|
|
|
try:
|
|
print("Checking public.transport_modes data...")
|
|
result = db.execute(text("SELECT * FROM public.transport_modes ORDER BY key ASC"))
|
|
rows = result.fetchall()
|
|
print(f"Found {len(rows)} records:")
|
|
for row in rows:
|
|
print(f"Key: {row[0]}, Name: {row[1]}")
|
|
|
|
if len(rows) == 0:
|
|
print("\nTable is empty! Inserting default values for testing...")
|
|
db.execute(text("INSERT INTO public.transport_modes (key, name) VALUES ('01', 'Marítimo'), ('02', 'Ferroviario'), ('03', 'Carretero'), ('04', 'Aéreo')"))
|
|
db.commit()
|
|
print("Inserted 4 default records.")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
# Try to see if table exists but schema is different
|
|
try:
|
|
result = db.execute(text("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"))
|
|
print("\nTables in public schema:")
|
|
for row in result:
|
|
print(f" - {row[0]}")
|
|
except:
|
|
pass
|