bmc_hub/test_billed_field.py

45 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Test billed_via_thehub_id opdatering"""
import sys
sys.path.insert(0, '/app')
from app.core.database import execute_query, execute_update
# Test query
print("\n=== Checking tmodule_times schema ===")
result = execute_query("""
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'tmodule_times'
AND column_name = 'billed_via_thehub_id'
""")
print(f"Column exists: {len(result) > 0}")
if result:
print(f" Type: {result[0]['data_type']}")
print(f" Nullable: {result[0]['is_nullable']}")
# Test foreign key
print("\n=== Checking foreign key constraint ===")
fk_result = execute_query("""
SELECT constraint_name, table_name, column_name
FROM information_schema.key_column_usage
WHERE table_name = 'tmodule_times'
AND column_name = 'billed_via_thehub_id'
""")
if fk_result:
print(f"Foreign key: {fk_result[0]['constraint_name']}")
# Check if there are any time entries
print("\n=== Sample time entries ===")
times = execute_query("""
SELECT id, status, billed_via_thehub_id, original_hours, worked_date
FROM tmodule_times
ORDER BY id DESC
LIMIT 5
""")
print(f"Found {len(times)} time entries:")
for t in times:
print(f" ID {t['id']}: status={t['status']}, billed_via={t['billed_via_thehub_id']}, hours={t['original_hours']}")
print("\n✅ Test complete!")