const seed = require('./seed/seed.json'); const Database = require('better-sqlite3'); const db = new Database('./data.db'); // Helper to get current timestamp const now = new Date().toISOString(); // 1. Seed Pages const insertPage = db.prepare(` INSERT OR REPLACE INTO ec_pages (id, slug, status, locale, title, subtitle, badge, hero_image, theme, show_cta, cta_text, cta_link, variant, size, created_at, updated_at, published_at) VALUES (?, ?, 'published', 'th', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `); (seed.content?.pages || []).forEach(p => { insertPage.run(p.id, p.slug, p.data.title, p.data.subtitle, p.data.badge, p.data.hero_image, p.data.theme, p.data.show_cta ? 1 : 0, p.data.cta_text, p.data.cta_link, p.data.variant, p.data.size, now, now, now); }); console.log('Pages seeded:', db.prepare('SELECT COUNT(*) as c FROM ec_pages').get().c); // 2. Seed Portfolio const insertPortfolio = db.prepare(` INSERT OR REPLACE INTO ec_portfolio (id, slug, status, locale, name, url, category, category_label, thumbnail, description, created_at, updated_at, published_at) VALUES (?, ?, 'published', 'th', ?, ?, ?, ?, ?, ?, ?, ?, ?) `); (seed.content?.portfolio || []).forEach((p, i) => { const pid = p.id || `portfolio-${String(i + 1).padStart(3, '0')}`; insertPortfolio.run(pid, p.slug, p.data.name, p.data.url, p.data.category, p.data.category_label, p.data.thumbnail, p.data.description, now, now, now); }); console.log('Portfolio seeded:', db.prepare('SELECT COUNT(*) as c FROM ec_portfolio').get().c); // 3. Seed Blog const insertBlog = db.prepare(` INSERT OR REPLACE INTO ec_blog (id, slug, status, locale, title, excerpt, image, date, category, content, created_at, updated_at, published_at) VALUES (?, ?, 'published', 'th', ?, ?, ?, ?, ?, ?, ?, ?, ?) `); (seed.content?.blog || []).forEach((p, i) => { const bid = p.id || `blog-${String(i + 1).padStart(3, '0')}`; insertBlog.run(bid, p.slug, p.data.title, p.data.excerpt, p.data.image, p.data.date, p.data.category, JSON.stringify(p.data.content), now, now, now); }); console.log('Blog seeded:', db.prepare('SELECT COUNT(*) as c FROM ec_blog').get().c); // 4. Seed FAQ const insertFaq = db.prepare(` INSERT OR REPLACE INTO ec_faq (id, slug, status, locale, category, question, answer, created_at, updated_at) VALUES (?, ?, 'published', 'th', ?, ?, ?, ?, ?) `); (seed.content?.faq || []).forEach((p, i) => { const fid = p.id || `faq-${String(i + 1).padStart(3, '0')}`; insertFaq.run(fid, p.slug || fid, p.data.category, p.data.question, p.data.answer, now, now); }); console.log('FAQ seeded:', db.prepare('SELECT COUNT(*) as c FROM ec_faq').get().c); db.close(); console.log('All seeding complete!');