def migrate(conn):
    cur = conn.cursor()
    cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='homepage_cards'")
    if cur.fetchone():
        return
    cur.execute("""
        CREATE TABLE homepage_cards (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            card_type TEXT NOT NULL,
            key TEXT NOT NULL,
            label_en TEXT,
            label_fr TEXT,
            image_path TEXT,
            prompt TEXT,
            sort_order INTEGER DEFAULT 0,
            is_active INTEGER DEFAULT 1,
            updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            UNIQUE(card_type, key)
        )
    """)
    body_styles = [
        ("Sedan", "Sedans", "Berlines",
         "Photorealistic hero image of a single modern sedan, bright airy showroom with soft natural daylight, 3/4 front angle, clean light neutral background, professional automotive photography, no text, no watermark, no logo, no other vehicles, no people."),
        ("SUV", "SUVs", "SUV",
         "Photorealistic hero image of a single modern SUV, bright airy showroom with soft natural daylight, 3/4 front angle, clean light neutral background, professional automotive photography, no text, no watermark, no logo, no other vehicles, no people."),
        ("Truck", "Trucks", "Camions",
         "Photorealistic hero image of a single modern pickup truck, bright airy showroom with soft natural daylight, 3/4 front angle, clean light neutral background, professional automotive photography, no text, no watermark, no logo, no other vehicles, no people."),
        ("Coupe", "Coupes", "Coupés",
         "Photorealistic hero image of a single modern coupe, bright airy showroom with soft natural daylight, 3/4 front angle, clean light neutral background, professional automotive photography, no text, no watermark, no logo, no other vehicles, no people."),
        ("Hatchback", "Hatchbacks", "À hayon",
         "Photorealistic hero image of a single modern hatchback, bright airy showroom with soft natural daylight, 3/4 front angle, clean light neutral background, professional automotive photography, no text, no watermark, no logo, no other vehicles, no people."),
        ("Van", "Vans", "Fourgonnettes",
         "Photorealistic hero image of a single modern van or minivan, bright airy showroom with soft natural daylight, 3/4 front angle, clean light neutral background, professional automotive photography, no text, no watermark, no logo, no other vehicles, no people."),
    ]
    for i, (key, en, fr, prompt) in enumerate(body_styles):
        cur.execute("""
            INSERT INTO homepage_cards (card_type, key, label_en, label_fr, prompt, sort_order)
            VALUES ('body_style', ?, ?, ?, ?, ?)
        """, (key, en, fr, prompt, i))
    makes = ["Toyota", "Honda", "Ford", "Hyundai", "Mazda", "Volkswagen", "Nissan", "Subaru"]
    for i, mk in enumerate(makes):
        cur.execute("""
            INSERT INTO homepage_cards (card_type, key, label_en, label_fr, prompt, sort_order)
            VALUES ('make', ?, ?, ?, ?, ?)
        """, (mk, mk, mk,
              f"Professional brand-neutral automotive showroom hero image representing {mk} vehicles - photorealistic, modern lighting, wide composition, no text, no watermark, no brand logo.",
              i))
    conn.commit()
