t3-oss / create-t3-app

The best way to start a full-stack, typesafe Next.js app
https://create.t3.gg
MIT License
24.88k stars 1.14k forks source link

bug: db:push throws "invalid url" #1822

Closed cchin25 closed 5 months ago

cchin25 commented 5 months ago

Provide environment information

System: OS: Linux 5.10 Ubuntu 20.04.6 LTS (Focal Fossa) CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor Memory: 14.36 GB / 15.57 GB Container: Yes Shell: 5.0.17 - /bin/bash Binaries: Node: 21.1.0 - ~/.nvm/versions/node/v21.1.0/bin/node npm: 10.2.0 - ~/.nvm/versions/node/v21.1.0/bin/npm pnpm: 8.6.2 - /usr/local/bin/pnpm bun: 1.0.0 - ~/.bun/bin/bun

Describe the bug

Creation flow halted because an "invalid url" error is thrown when trying to create a local sqlite db.

Reproduction repo

n/a

To reproduce

Repro:

npm create t3-app@latest

◇  What will your project be called?
│  my-proj
│
◇  Will you be using TypeScript or JavaScript?
│  TypeScript
│
◇  Will you be using Tailwind CSS for styling?
│  Yes
│
◇  Would you like to use tRPC?
│  Yes
│
◇  What authentication provider would you like to use?
│  NextAuth.js
│
◇  What database ORM would you like to use?
│  Drizzle
│
◇   EXPERIMENTAL  Would you like to use Next.js App Router?
│  Yes
│
◇  What database provider would you like to use?
│  SQLite
│
◇  Should we initialize a Git repository and stage the changes?
│  Yes
│
◇  Should we run 'npm install' for you?
│  Yes
│
◇  What import alias would you like to use?
│  ~/

Using: npm

✔ my-proj scaffolded successfully!

Adding boilerplate...
✔ Successfully setup boilerplate for nextAuth
✔ Successfully setup boilerplate for drizzle
✔ Successfully setup boilerplate for tailwind
✔ Successfully setup boilerplate for trpc
✔ Successfully setup boilerplate for envVariables
✔ Successfully setup boilerplate for eslint

Follow "Next Steps"

  cd my-proj
  npm run db:push
  npm run dev
  git commit -m "initial commit"

Receive the following error:

> my-proj@0.1.0 db:push
> drizzle-kit push:sqlite

No config path provided, using default path
Reading config file '/home/{username}/repos/my-proj/drizzle.config.ts'
❌ Invalid environment variables: { DATABASE_URL: [ 'Invalid url' ] }
drizzle-kit: v0.20.14
drizzle-orm: v0.29.5

/home/{username}/repos/my-proj/node_modules/@t3-oss/env-core/dist/index.js:29
        throw new Error("Invalid environment variables");
              ^
Error: Invalid environment variables
    at onValidationError (/home/{username}/repos/my-proj/node_modules/@t3-oss/env-core/dist/index.js:29:15)
    at createEnv (/home/{username}/repos/my-proj/node_modules/@t3-oss/env-core/dist/index.js:35:16)
    at createEnv (/home/{username}/repos/my-proj/node_modules/@t3-oss/env-nextjs/dist/index.js:12:12)
    at Object.<anonymous> (/home/{username}/repos/my-proj/src/env.js:4:20)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._compile (/home/{username}/repos/my-proj/node_modules/drizzle-kit/bin.cjs:8644:30)
    at extensions..js (/home/{username}/repos/my-proj/node_modules/drizzle-kit/bin.cjs:11183:20)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)

Node.js v21.1.0

Uses default .env

# When adding additional environment variables, the schema in "/src/env.js"
# should be updated accordingly.

# Drizzle
DATABASE_URL="db.sqlite"

# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
# NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000"

# Next Auth Discord Provider
DISCORD_CLIENT_ID="REDACTED"
DISCORD_CLIENT_SECRET="REDACTED"

Changing the DATABASE_URL to file:db.sqlite will generate a db file, but the file name is literally file:db.sqlite

My expectation would be when I run npm run db:push a file named db.sqlite is generated at the root of my project.

Additional information

No response

flowergardn commented 5 months ago

I'm not too familiar with Drizzle, but this behavior seems to be intentional? image

Ideally there shouldn't be a ternary here though

cchin25 commented 5 months ago

I switched to the libsql driver, and it works as expected.

ezra-en commented 5 months ago

encountered the same issue, can verify switching to libsql gets things going. Used DATABASE_URL="file:./db.sqlite" and it placed the file in the project root as expected.

kom-senapati commented 5 months ago

encountered the same issue, can verify switching to libsql gets things going. Used DATABASE_URL="file:./db.sqlite" and it placed the file in the project root as expected.

How to use libsql here we have to change some file ?

ezra-en commented 5 months ago

@kom-senapati in your drizzle.config.ts, edit to driver: 'libsql', then npm install @libsql/client, and finally in your .env write: DATABASE_URL="file:./db.sqlite"

juliusmarminge commented 5 months ago

anyone wanna file a pr swapping better-sqlite with libsql?