import sqlite3 conn = sqlite3.connect('D:/Workspace/claudeCode/AutonetSellCar.com/backend/car_platform.db') cursor = conn.cursor() # List all tables cursor.execute("SELECT name FROM sqlite_master WHERE type='table'") tables = cursor.fetchall() print('Tables in database:') for t in tables: print(f' - {t[0]}') # Check if inquiries table exists if ('inquiries',) not in tables: print('\nCreating inquiries table...') cursor.execute(''' CREATE TABLE inquiries ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, car_id INTEGER, category VARCHAR(50) DEFAULT "general", subject VARCHAR(200), message TEXT NOT NULL, contact_email VARCHAR(255), contact_phone VARCHAR(50), status VARCHAR(20) DEFAULT "pending", admin_response TEXT, responded_at DATETIME, responded_by INTEGER, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME, FOREIGN KEY (user_id) REFERENCES users (id), FOREIGN KEY (car_id) REFERENCES cars (id) ) ''') print('inquiries table created!') else: print('\nChecking columns in inquiries table...') cursor.execute('PRAGMA table_info(inquiries)') columns = cursor.fetchall() existing_cols = [col[1] for col in columns] print('Existing columns:', existing_cols) # Add new columns if they don't exist new_columns = [ ('category', 'VARCHAR(50) DEFAULT "general"'), ('subject', 'VARCHAR(200)'), ('contact_email', 'VARCHAR(255)'), ('contact_phone', 'VARCHAR(50)'), ('admin_response', 'TEXT'), ('responded_at', 'DATETIME'), ('responded_by', 'INTEGER'), ('updated_at', 'DATETIME'), ] for col_name, col_type in new_columns: if col_name not in existing_cols: try: cursor.execute(f'ALTER TABLE inquiries ADD COLUMN {col_name} {col_type}') print(f'Added column: {col_name}') except Exception as e: print(f'Error adding {col_name}: {e}') # Create inquiry_messages table if not exists cursor.execute(''' CREATE TABLE IF NOT EXISTS inquiry_messages ( id INTEGER PRIMARY KEY AUTOINCREMENT, inquiry_id INTEGER NOT NULL, user_id INTEGER NOT NULL, message TEXT NOT NULL, is_admin BOOLEAN DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (inquiry_id) REFERENCES inquiries (id), FOREIGN KEY (user_id) REFERENCES users (id) ) ''') print('\ninquiry_messages table created/verified') conn.commit() conn.close() print('\nDatabase update complete!')