import { createClient } from '@supabase/supabase-js' import { products } from '../src/data/products.js' import { services } from '../src/data/services.js' const supabaseUrl = process.env.SUPABASE_URL const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY if (!supabaseUrl || !serviceRoleKey) { console.error('Set SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY environment variables before running this script.') process.exit(1) } const supabase = createClient(supabaseUrl, serviceRoleKey) function toStoragePath(image: string): string { return image.replace(/^\//, '') } async function seed() { const productRows = products.map(({ id, name, category, price, image, description, inStock }) => ({ id, name, category, price, image: toStoragePath(image), description, in_stock: inStock, })) const { error: productsError } = await supabase.from('products').upsert(productRows) if (productsError) throw productsError const serviceRows = services.map(({ id, name, durationMinutes, priceFrom, description, image }) => ({ id, name, duration_minutes: durationMinutes, price_from: priceFrom, description, image: toStoragePath(image), })) const { error: servicesError } = await supabase.from('services').upsert(serviceRows) if (servicesError) throw servicesError const { error: scheduleError } = await supabase.from('schedule_template').upsert({ id: 'default', working_days: [2, 3, 4, 5, 6], start_time: '09:00', end_time: '18:00', slot_minutes: 120, }) if (scheduleError) throw scheduleError console.log(`Seeded ${products.length} products, ${services.length} services, and the default schedule.`) } seed().catch((err) => { console.error(err) process.exit(1) })