initial
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 09:21:14 +01:00
commit 194330fb47
40 changed files with 11873 additions and 0 deletions

148
packages/db/src/seed.ts Executable file
View File

@@ -0,0 +1,148 @@
import { db } from "./index";
import {
adventureItems,
adventureTemplates,
spiritualConfig,
userProgress,
users,
settings,
} from "./schema";
const DEFAULT_PRAYER = [
"Morning",
"Midday",
"Evening",
"Rosary",
"Examen",
];
const DEFAULT_LITANIES = [
"Litany 1",
"Litany 2",
"Litany 3",
"Litany 4",
"Litany 5",
"Litany 6",
];
async function seed() {
const existing = await db.select().from(users).limit(1);
if (existing.length > 0) {
console.log("User already exists, skipping seed.");
return;
}
const [user] = await db
.insert(users)
.values({ displayName: "Traveler" })
.returning();
await db.insert(userProgress).values({ userId: user.id });
await db.insert(spiritualConfig).values({
userId: user.id,
prayerLabels: DEFAULT_PRAYER,
litanyLabels: DEFAULT_LITANIES,
});
await db.insert(settings).values([
{ userId: user.id, key: "weekly_reading_goal", value: 50 },
{ userId: user.id, key: "notifications_enabled", value: false },
{ userId: user.id, key: "sounds_enabled", value: false },
{ userId: user.id, key: "theme", value: "minimal-dark" },
]);
const templates = [
{
name: "Weekday",
daysOfWeek: [1, 2, 3, 4, 5],
isDefault: true,
isSystem: true,
sortPriority: 0,
items: [
{ type: "duration", label: "Work", config: { targetHours: 7.5 }, sortOrder: 0 },
{ type: "checkbox", label: "Exercise", config: {}, sortOrder: 1 },
{ type: "reading", label: "Read", config: {}, sortOrder: 2 },
{ type: "timeblock", label: "Class 1", config: { scheduledTime: "18:00" }, sortOrder: 3 },
{ type: "timeblock", label: "Class 2", config: { scheduledTime: "20:00" }, sortOrder: 4 },
{ type: "checklist", label: "Prayer", config: { checklistSize: 5 }, sortOrder: 5 },
{ type: "checklist", label: "Litanies", config: { checklistSize: 6 }, sortOrder: 6 },
{ type: "note", label: "Notes", config: {}, sortOrder: 7 },
],
},
{
name: "Saturday",
daysOfWeek: [6],
isDefault: false,
isSystem: true,
sortPriority: 0,
items: [
{ type: "checkbox", label: "Exercise", config: {}, sortOrder: 0 },
{ type: "reading", label: "Read", config: {}, sortOrder: 1 },
{ type: "checklist", label: "Prayer", config: { checklistSize: 5 }, sortOrder: 2 },
{ type: "checklist", label: "Litanies", config: { checklistSize: 6 }, sortOrder: 3 },
{ type: "note", label: "Notes", config: {}, sortOrder: 4 },
],
},
{
name: "Sunday",
daysOfWeek: [0],
isDefault: false,
isSystem: true,
sortPriority: 0,
items: [
{ type: "reading", label: "Read", config: {}, sortOrder: 0 },
{ type: "checkbox", label: "Exercise", config: {}, sortOrder: 1 },
{ type: "checklist", label: "Prayer", config: { checklistSize: 5 }, sortOrder: 2 },
{ type: "checklist", label: "Litanies", config: { checklistSize: 6 }, sortOrder: 3 },
{ type: "note", label: "Notes", config: {}, sortOrder: 4 },
],
},
{
name: "Teaching Day",
daysOfWeek: [2, 4],
isDefault: false,
isSystem: true,
sortPriority: 10,
items: [
{ type: "duration", label: "Work", config: { targetHours: 7.5 }, sortOrder: 0 },
{ type: "checkbox", label: "Teaching", config: {}, sortOrder: 1 },
{ type: "checkbox", label: "Exercise", config: {}, sortOrder: 2 },
{ type: "reading", label: "Read", config: {}, sortOrder: 3 },
{ type: "checklist", label: "Prayer", config: { checklistSize: 5 }, sortOrder: 4 },
{ type: "checklist", label: "Litanies", config: { checklistSize: 6 }, sortOrder: 5 },
],
},
];
for (const tpl of templates) {
const [template] = await db
.insert(adventureTemplates)
.values({
userId: user.id,
name: tpl.name,
daysOfWeek: tpl.daysOfWeek,
isDefault: tpl.isDefault,
isSystem: tpl.isSystem,
sortPriority: tpl.sortPriority,
})
.returning();
for (const item of tpl.items) {
await db.insert(adventureItems).values({
templateId: template.id,
type: item.type,
label: item.label,
config: item.config,
sortOrder: item.sortOrder,
});
}
}
console.log("Seed complete. User ID:", user.id);
}
seed()
.then(() => process.exit(0))
.catch((err) => {
console.error(err);
process.exit(1);
});