#!/usr/bin/env python
"""Check database connection and get database name"""
import django
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from django.db import connection

try:
    with connection.cursor() as cursor:
        cursor.execute('SELECT DATABASE()')
        db_name = cursor.fetchone()[0]
        print(f'Connected to database: {db_name}')
        
        cursor.execute('SHOW TABLES')
        tables = cursor.fetchall()
        print(f'Number of tables: {len(tables)}')
        
        if len(tables) > 0:
            print('Sample tables:', [t[0] for t in tables[:5]])
except Exception as e:
    print(f'Error: {e}')
