// Seed data script for initial locations and categories
// Run with: npx sanity exec seed-data.ts --with-user-token
import { getCliClient } from 'sanity/cli';
const client = getCliClient();
const locations = [
{
_type: 'location',
city: 'Oslo',
slug: { _type: 'slug', current: 'oslo' },
region: 'Oslo',
country: 'Norge',
coordinates: { _type: 'geopoint', lat: 59.9139, lng: 10.7522 },
timezone: 'Europe/Oslo',
locationType: 'city',
},
{
_type: 'location',
city: 'Bergen',
slug: { _type: 'slug', current: 'bergen' },
region: 'Vestland',
country: 'Norge',
coordinates: { _type: 'geopoint', lat: 60.3913, lng: 5.3221 },
timezone: 'Europe/Oslo',
locationType: 'city',
},
];
const categories = [
{
_type: 'category',
name: 'Musikk',
slug: { _type: 'slug', current: 'musikk' },
icon: '🎵',
color: '#FF6B6B',
},
{
_type: 'category',
name: 'Sport',
slug: { _type: 'slug', current: 'sport' },
icon: '⚽',
color: '#4ECDC4',
},
{
_type: 'category',
name: 'Kunst & Kultur',
slug: { _type: 'slug', current: 'kunst-kultur' },
icon: '🎨',
color: '#9B59B6',
},
{
_type: 'category',
name: 'Mat & Drikke',
slug: { _type: 'slug', current: 'mat-drikke' },
icon: '🍽️',
color: '#F39C12',
},
{
_type: 'category',
name: 'Networking',
slug: { _type: 'slug', current: 'networking' },
icon: '🤝',
color: '#3498DB',
},
{
_type: 'category',
name: 'Familie',
slug: { _type: 'slug', current: 'familie' },
icon: '👨👩👧👦',
color: '#2ECC71',
},
];
async function seedData() {
console.log('Seeding locations...');
for (const location of locations) {
const existing = await client.fetch(
`*[_type == "location" && slug.current == $slug][0]`,
{ slug: location.slug.current }
);
if (!existing) {
await client.create(location);
console.log(`Created location: ${location.city}`);
} else {
console.log(`Location exists: ${location.city}`);
}
}
console.log('\nSeeding categories...');
for (const category of categories) {
const existing = await client.fetch(
`*[_type == "category" && slug.current == $slug][0]`,
{ slug: category.slug.current }
);
if (!existing) {
await client.create(category);
console.log(`Created category: ${category.name}`);
} else {
console.log(`Category exists: ${category.name}`);
}
}
console.log('\nSeeding complete!');
}
seedData().catch(console.error);