28 lines
906 B
JavaScript
28 lines
906 B
JavaScript
/// seeds/banners.js
|
|
const banners = [
|
|
{ id: 'b-1', title: '为肛肠/胃肠健康护航', subtitle: '三甲名医亲诊', image: 'https://picsum.photos/id/1015/750/400', link: '/pages/appointment/index', sort: 1, enabled: 1 }
|
|
];
|
|
|
|
const seedBanners = async (pool) => {
|
|
const conn = await pool.getConnection();
|
|
try {
|
|
const [rows] = await conn.query('SELECT COUNT(*) AS c FROM banners');
|
|
if (rows[0].c > 0) {
|
|
console.log('[Seed] banners: skipped (already has data)');
|
|
return;
|
|
}
|
|
for (const b of banners) {
|
|
await conn.query(
|
|
`INSERT INTO banners (id, title, subtitle, image, link, sort, enabled)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
[b.id, b.title, b.subtitle, b.image, b.link, b.sort, b.enabled]
|
|
);
|
|
}
|
|
console.log(`[Seed] banners: inserted ${banners.length}`);
|
|
} finally {
|
|
conn.release();
|
|
}
|
|
};
|
|
|
|
module.exports = { seedBanners };
|