feat: seed default user sources (#128)

This commit is contained in:
2026-06-14 14:26:10 +01:00
committed by GitHub
parent 112d482d55
commit 789b6a285b
10 changed files with 220 additions and 8 deletions

View File

@@ -0,0 +1,30 @@
import { LocationSource } from "@freya/source-location"
import { WebSearchSource } from "@freya/source-web-search"
import type { Database } from "../db/index.ts"
import { userSources } from "../db/schema.ts"
export const DEFAULT_ENABLED_SOURCE_IDS = [LocationSource.id, WebSearchSource.id] as const
export type DefaultEnabledSourceId = (typeof DEFAULT_ENABLED_SOURCE_IDS)[number]
export async function insertDefaultUserSources(db: Database, userId: string): Promise<void> {
const now = new Date()
await db
.insert(userSources)
.values(
DEFAULT_ENABLED_SOURCE_IDS.map((sourceId) => ({
userId,
sourceId,
enabled: true,
config: {},
createdAt: now,
updatedAt: now,
})),
)
.onConflictDoNothing({
target: [userSources.userId, userSources.sourceId],
})
}