-
Notifications
You must be signed in to change notification settings - Fork 0
improve: tighten ingestion and SDK types #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,48 @@ | ||
| import { drizzle } from "drizzle-orm/neon-http"; | ||
| import { neon } from "@neondatabase/serverless"; | ||
| import { events, resume, visitors, visitorEvents } from "./schema"; | ||
| import { events, visitors } from "./schema"; | ||
|
|
||
| function getDbClient() { | ||
| function createDb(databaseUrl: string) { | ||
| const sql = neon(databaseUrl); | ||
| return drizzle(sql, { schema: { events, visitors } }); | ||
| } | ||
|
|
||
| type DbClient = ReturnType<typeof createDb>; | ||
|
|
||
| function createFallbackDb(): DbClient { | ||
| return { | ||
| select() { | ||
| return { | ||
| from() { | ||
| return []; | ||
| }, | ||
| }; | ||
| }, | ||
| insert() { | ||
| return { | ||
| values() { | ||
| return { | ||
| returning() { | ||
| return []; | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| }, | ||
| async execute() { | ||
| return { rows: [] }; | ||
| }, | ||
| } as unknown as DbClient; | ||
| } | ||
|
|
||
| function getDbClient(): DbClient { | ||
| const databaseUrl = process.env.DATABASE_URL; | ||
|
|
||
| if (!databaseUrl) { | ||
| // Return dummy client during build or test if url is missing, or if env not set | ||
| return { | ||
| select: () => ({ from: () => [] }), | ||
| insert: () => ({ values: () => ({ returning: () => [] }) }), | ||
| execute: async () => ({ rows: [] }), | ||
| } as any; | ||
| return createFallbackDb(); | ||
| } | ||
|
|
||
| const sql = neon(databaseUrl); | ||
| return drizzle(sql, { schema: { events, resume, visitors, visitorEvents } }); | ||
| return createDb(databaseUrl); | ||
| } | ||
|
|
||
| export const db = getDbClient(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,4 @@ | ||
| export { events } from "./schema"; | ||
| export { resume, visitors, visitorEvents } from "./schema"; | ||
| export type { | ||
| Event, | ||
| NewEvent, | ||
| Resume, | ||
| NewResume, | ||
| Visitor, | ||
| NewVisitor, | ||
| VisitorEvent, | ||
| NewVisitorEvent, | ||
| } from "./schema"; | ||
| export { visitors } from "./schema"; | ||
| export type { Event, NewEvent, Visitor, NewVisitor } from "./schema"; | ||
| export { db } from "./client"; |
10 changes: 10 additions & 0 deletions
10
apps/ingestion/src/db/migrations/0001_archive_legacy_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| DO $$ | ||
| BEGIN | ||
| IF to_regclass('public.resume') IS NOT NULL AND to_regclass('public.old_resume') IS NULL THEN | ||
| ALTER TABLE public.resume RENAME TO old_resume; | ||
| END IF; | ||
|
|
||
| IF to_regclass('public.visitor_events') IS NOT NULL AND to_regclass('public.old_visitor_events') IS NULL THEN | ||
| ALTER TABLE public.visitor_events RENAME TO old_visitor_events; | ||
| END IF; | ||
| END $$; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Fallback DB client shape diverges from the real drizzle client and may cause subtle runtime differences.
The fallback client is cast to
DbClient, but its query methods are synchronous and return plain arrays/objects, while the real drizzle client returns Promises (e.g.select().from(),insert().values().returning()). This can break code that uses Promise-specific behavior (.then,Promise.all, assuming asyncexecute()). Consider making these methodsasyncand returning Promise-based results that mirror drizzle’s shapes to keep the async contract consistent.