"""
Migration script to add dealer_description translation columns to cars table
Run: python migrate_translations.py
"""
import sqlite3
import os

# DB path
DB_PATH = os.path.join(os.path.dirname(__file__), 'autonet.db')

def migrate():
    print(f"Connecting to: {DB_PATH}")
    conn = sqlite3.connect(DB_PATH)
    cursor = conn.cursor()

    # Check existing columns
    cursor.execute('PRAGMA table_info(cars)')
    columns = [col[1] for col in cursor.fetchall()]
    print(f"Existing columns: {len(columns)} columns")

    # New columns to add
    new_columns = [
        ('dealer_description_en', 'TEXT'),
        ('dealer_description_mn', 'TEXT'),
        ('dealer_description_ru', 'TEXT')
    ]

    for col_name, col_type in new_columns:
        if col_name not in columns:
            cursor.execute(f'ALTER TABLE cars ADD COLUMN {col_name} {col_type}')
            print(f'Added column: {col_name}')
        else:
            print(f'Column already exists: {col_name}')

    conn.commit()
    conn.close()
    print('Migration complete!')

if __name__ == '__main__':
    migrate()
