65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const stationsPath = path.join(__dirname, 'stations.json');
|
|
|
|
if (!fs.existsSync(stationsPath)) {
|
|
console.warn(`Stations file not found at ${stationsPath}. Skipping seed.`);
|
|
return;
|
|
}
|
|
|
|
const raw = fs.readFileSync(stationsPath, 'utf-8');
|
|
const data = JSON.parse(raw);
|
|
|
|
const groups = {};
|
|
for (const group of data.groups || []) {
|
|
groups[group.id] = group.name || 'Unknown';
|
|
}
|
|
|
|
const stations = data.stations || [];
|
|
console.log(`Seeding ${stations.length} stations...`);
|
|
|
|
let count = 0;
|
|
for (const s of stations) {
|
|
const groupName = groups[s.groupId] || 'Unknown';
|
|
await prisma.station.upsert({
|
|
where: { stationId: s.id },
|
|
update: {
|
|
name: s.name,
|
|
streamUrl: s.stream,
|
|
genre: groupName,
|
|
tags: [groupName],
|
|
sortOrder: count,
|
|
source: 'local',
|
|
},
|
|
create: {
|
|
stationId: s.id,
|
|
name: s.name,
|
|
prefix: '',
|
|
streamUrl: s.stream,
|
|
coverUrl: null,
|
|
genre: groupName,
|
|
tags: [groupName],
|
|
sortOrder: count,
|
|
source: 'local',
|
|
},
|
|
});
|
|
count++;
|
|
}
|
|
|
|
console.log(`Seeded ${count} stations.`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|