Skip to content
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

[BUG]: Missing d1 as a valid input for driver #2292

Closed
oliwerhelsen opened this issue May 10, 2024 · 9 comments
Closed

[BUG]: Missing d1 as a valid input for driver #2292

oliwerhelsen opened this issue May 10, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@oliwerhelsen
Copy link

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.0

Describe the Bug

Following the documentation for migrating to D1 i'm getting the following error:
Invalid input Either "turso", "libsql", "better-sqlite" are available options for "--driver"

Using this setup:

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "sqlite",
  driver: "d1", // The docs says "d1-http" but that's gives me an type error
  dbCredentials: {
    wranglerConfigPath: "wrangler.toml",
    dbName: "products",
  },
  schema: "./src/schema/*",
  out: "./drizzle",
}) satisfies Config;

Works fine to generate, but not migrate.

### Expected behavior

d1 to exist as a valid driver

### Environment & setup

_No response_
@oliwerhelsen oliwerhelsen added the bug Something isn't working label May 10, 2024
@collinstommy
Copy link

I'm getting type errors but this at config at least launches for drizzle studio for me

export default {
  schema: "./src/db/schema.ts",
  out: "./drizzle",
  dialect: "sqlite",
  driver: "d1-http",
  dbCredentials: {
    url: ".wrangler/state/v3/d1/miniflare-D1DatabaseObject/<id>,
  },
} satisfies Config;

@they-cloned-me
Copy link

Same issue. Here is my setup 👇🏿

{
  “dependencies": {
    “drizzle-orm": "^0.30.10"
  },
  “devDependencies": {
    “drizzle-kit": "^0.21.2"
  }
}
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./server/database/schema",
  out: "./server/database/migrations",
  dialect: "sqlite", // <-- No good, even with this. Is this even required? 🤔
  driver: "d1",
  dbCredentials: {
    wranglerConfigPath: "./wrangler.toml",
    dbName: "coolkatznotrealdbname”,
  },
});

Invalid input Either "turso", "libsql", "better-sqlite" are available options for "--driver"

@kossnocorp
Copy link

kossnocorp commented May 22, 2024

I have the same issue with a barebone setup. @collinstommy approach worked for me with slight adjustments:

import { defineConfig } from "drizzle-kit";

const isStudio = process.argv.includes("studio");

// [TODO] Always use "d1" driver when there's a solution for the issue: https://github.com/drizzle-team/drizzle-orm/issues/2292
//   driver: "d1",
//     dbCredentials: {
//     wranglerConfigPath: "./../../apps/web/wrangler.toml",
//     dbName: "main",
//   },
export default defineConfig({
  schema: "./schema.ts",
  out: "./drizzle",
  dialect: "sqlite",
  ...(isStudio
    ? {
        driver: "d1-http",
        dbCredentials: {
          wranglerConfigPath: "./../../apps/web/wrangler.toml",
          url: "file:./../../apps/web/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/YOUR_DB_ID.sqlite",
        },
      }
    : {
        driver: "d1",
        dbCredentials: {
          wranglerConfigPath: "./../../apps/web/wrangler.toml",
          dbName: "main",
        },
      }),
});

I added file: to the url option as without it was throwing URL_INVALID and also check if it's a studio command in order to make drizzle-kit generate work.

@AndriiSherman
Copy link
Member

This should be fixed in drizzle-kit@0.21.3. If the issue persists, feel free to reopen it!

@imumesh18
Copy link

Hey @AndriiSherman I am trying with drizzle-kit@0.21.3 but still getting the same error.

bun db:migrate
$ drizzle-kit migrate
drizzle-kit: v0.21.3
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file '/workspaces/umesh.dev/drizzle.config.ts'
 Invalid input  Either "turso", "libsql", "better-sqlite" are available options for "--driver"
error: script "db:migrate" exited with code 1

Also here is the config

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/db/schema.ts",
  out: "./migrations",
  dialect: "sqlite",
  driver: "d1",
  dbCredentials: {
    wranglerConfigPath: "./wrangler.toml",
    dbName: "production_db",
  },
  verbose: true,
  strict: true,
  schemaFilter: ["public"],
  migrations: {
    table: "migrations",
    schema: "public",
  },
});

Apart from generate and check none of the commands like migrate, pull, push, studio seem to work.

@Akkuma
Copy link

Akkuma commented May 22, 2024

I also can confirm still seeing this @AndriiSherman
image

@AlexBlokh
Copy link
Contributor

@Akkuma @imumesh18
it's driver: 'd1-http', ts should've suggested, please restart ts server
we will update error text respectfully

@Akkuma
Copy link

Akkuma commented May 22, 2024

@Akkuma @imumesh18 it's driver: 'd1-http', ts should've suggested, please restart ts server we will update error text respectfully

That worked. Yea reloading TS server was the ticket since it still said 'd1' was valid. Is there a way to choose whether to use local vs remote DBs like leveraging studio on the local data?

@AlexBlokh
Copy link
Contributor

AlexBlokh commented May 22, 2024

you should have 2 separate drizzle configs for remote and local
and then just

drizzle-kit studio --config drizzle.local.config.ts
drizzle-kit studio --config drizzle.config.ts // default, could omit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants