-
-
Notifications
You must be signed in to change notification settings - Fork 29
Switch from @astrojs/db to drizzle #45
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 was deleted.
Oops, something went wrong.
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
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,15 @@ | ||
| import { drizzle } from 'drizzle-orm/libsql'; | ||
|
|
||
| import * as schema from './schema'; | ||
|
|
||
| // Uses ASTRO_DB_REMOTE_URL and ASTRO_DB_APP_TOKEN from environment. | ||
| // In Astro files, these are available via import.meta.env. | ||
| // In standalone scripts (seed), they are loaded via process.env. | ||
| export function createDb(url: string, authToken: string) { | ||
| return drizzle({ | ||
| connection: { url, authToken }, | ||
| schema | ||
| }); | ||
| } | ||
|
|
||
| export type Database = ReturnType<typeof createDb>; |
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,62 @@ | ||
| import { | ||
| integer, | ||
| sqliteTable, | ||
| text, | ||
| uniqueIndex | ||
| } from 'drizzle-orm/sqlite-core'; | ||
|
|
||
| export const Episode = sqliteTable('Episode', { | ||
| episodeSlug: text().primaryKey() | ||
| }); | ||
|
|
||
| export const Person = sqliteTable('Person', { | ||
| id: text().primaryKey(), | ||
| img: text(), | ||
| name: text().notNull() | ||
| }); | ||
|
|
||
| export const HostOrGuest = sqliteTable( | ||
| 'HostOrGuest', | ||
| { | ||
| _id: integer('_id').primaryKey(), | ||
| episodeSlug: text() | ||
| .notNull() | ||
| .references(() => Episode.episodeSlug), | ||
| isHost: integer({ mode: 'boolean' }).notNull(), | ||
| personId: text() | ||
| .notNull() | ||
| .references(() => Person.id) | ||
| }, | ||
| (table) => [ | ||
| uniqueIndex('HostOrGuest_episodeSlug_personId_idx').on( | ||
| table.episodeSlug, | ||
| table.personId | ||
| ) | ||
| ] | ||
| ); | ||
|
|
||
| export const Sponsor = sqliteTable('Sponsor', { | ||
| id: text().primaryKey(), | ||
| img: text(), | ||
| name: text().notNull(), | ||
| url: text().notNull() | ||
| }); | ||
|
|
||
| export const SponsorForEpisode = sqliteTable( | ||
| 'SponsorForEpisode', | ||
| { | ||
| _id: integer('_id').primaryKey(), | ||
| episodeSlug: text() | ||
| .notNull() | ||
| .references(() => Episode.episodeSlug), | ||
| sponsorId: text() | ||
| .notNull() | ||
| .references(() => Sponsor.id) | ||
| }, | ||
| (table) => [ | ||
| uniqueIndex('SponsorForEpisode_episodeSlug_sponsorId_idx').on( | ||
| table.episodeSlug, | ||
| table.sponsorId | ||
| ) | ||
| ] | ||
| ); |
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineConfig } from 'drizzle-kit'; | ||
|
|
||
| export default defineConfig({ | ||
| schema: './db/schema.ts', | ||
| out: './drizzle', | ||
| dialect: 'turso', | ||
| dbCredentials: { | ||
| url: process.env.ASTRO_DB_REMOTE_URL!, | ||
| authToken: process.env.ASTRO_DB_APP_TOKEN! | ||
| } | ||
| }); | ||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 216
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 877
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 641
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 47
🏁 Script executed:
# Check the actual drizzle.config.ts more carefully for any dotenv loading cat -n drizzle.config.tsRepository: shipshapecode/starpod
Length of output: 401
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 47
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 130
🏁 Script executed:
Repository: shipshapecode/starpod
Length of output: 81
🌐 Web query:
drizzle-kit .env automatic loading environment variables💡 Result:
Drizzle-kit does not automatically load environment variables from .env files by default. Users must manually load them in the drizzle.config.ts (or .js) file using a library like dotenv. To enable .env loading: 1. Install dotenv: npm i -D dotenv 2. In drizzle.config.ts: import * as dotenv from "dotenv"; dotenv.config({ path: ".env.local" }); // or appropriate .env file import type { Config } from "drizzle-kit"; export default { schema: "./src/db/schema.ts", out: "./drizzle", dialect: "postgresql", dbCredentials: { url: process.env.DATABASE_URL!, }, } satisfies Config; For Next.js projects, use
@next/envinstead: import { loadEnvConfig } from "@next/env"; loadEnvConfig("./"); Alternative approaches: - Use Node.js --env-file flag (Node v20.6+): node --env-file=.env.local ./node_modules/drizzle-kit/bin.cjs generate - Prefix commands: dotenv -e .env.local -- drizzle-kit generate A GitHub discussion (#3405) from Nov 2024 announced planned built-in support for automatic .env loading (including .env*, .env.local based on NODE_ENV, --env-file, --no-env flags), using dotenvx. Some users report it "working out of the box" in recent versions (e.g., 0.30.5+), and logs show "Env file: .env.development.local", but official docs do not confirm full implementation as of 2026-03-27. Check latest changelog or test npx drizzle-kit push to verify if automatic loading is active in your version. Official docs recommend manual dotenv import for dbCredentials.Citations:
Add dotenv loading to drizzle.config.ts to ensure environment variables are available when running drizzle-kit commands.
Drizzle Kit doesn't automatically load
.envfiles. The configuration referencesprocess.env.ASTRO_DB_REMOTE_URLandprocess.env.ASTRO_DB_APP_TOKENwithout loading them, which means these values will be undefined unless set externally (e.g., in CI/CD or shell environment). This is inconsistent withdb/seed.ts, which already importsdotenv/config.Solution: Add dotenv import
+import 'dotenv/config'; import { defineConfig } from 'drizzle-kit'; export default defineConfig({🤖 Prompt for AI Agents