-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.ts
More file actions
60 lines (53 loc) · 1.82 KB
/
seed.ts
File metadata and controls
60 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/postgres-js';
import { hash } from 'bcrypt';
import * as schema from './src/lib/server/db/schema';
const client = postgres(process.env.DATABASE_URL!);
const db = drizzle(client, { schema, casing: 'camelCase' });
async function seed() {
const username = process.env.ADMIN_USERNAME || 'admin';
const password = process.env.ADMIN_PASSWORD || 'changeme';
const passwordHash = await hash(password, 10);
await db.insert(schema.adminUsers).values({
username,
passwordHash
}).onConflictDoNothing();
// Sample event
const [event] = await db.insert(schema.events).values({
title: 'javaBin Kids Høst 2026',
description: 'En kveld med koding og robotprogrammering for barn! Vi har aktiviteter tilpasset ulike aldersgrupper.',
date: new Date('2026-09-04T17:00:00'),
location: 'NOVA Spektrum, Lillestrøm',
registrationOpens: new Date('2026-06-01T00:00:00'),
registrationCloses: new Date('2026-09-03T23:59:59')
}).returning();
await db.insert(schema.courses).values([
{
arrangementId: event.arrangementId,
title: 'Scratch for nybegynnere',
description: 'Lær å programmere med Scratch! Lag ditt eget spill med blokk-programmering.',
ageMin: 6,
ageMax: 9,
maxParticipants: 20
},
{
arrangementId: event.arrangementId,
title: 'Robotprogrammering med micro:bit',
description: 'Programmer micro:bit til å styre roboter! Lær om sensorer og motorer.',
ageMin: 8,
ageMax: 12,
maxParticipants: 15
},
{
arrangementId: event.arrangementId,
title: 'Webutvikling med HTML og CSS',
description: 'Lag din egen nettside fra bunnen av. Lær grunnleggende HTML og CSS.',
ageMin: 10,
ageMax: 14,
maxParticipants: 20
}
]);
console.log('Seed completed successfully');
await client.end();
}
seed().catch(console.error);