drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too πŸ˜…
https://orm.drizzle.team
Apache License 2.0
23.51k stars 576 forks source link

[BUG]: Turso Introspection is empty #2483

Open sscotth opened 3 months ago

sscotth commented 3 months ago

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

0.22.6

Describe the Bug

I created a Turso database drizzle-test with a simple table untitled_table_1 with two columns.

export const temp = sqliteTable('untitled_table_1', {
  id: text('id').primaryKey(),
  name: text('name').notNull(),
})
> npx drizzle-kit push
drizzle-kit: v0.22.6
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file '.../drizzle.config.ts'
[βœ“] Pulling schema from database...
 Warning  You are about to execute current statements:

CREATE TABLE `untitled_table_1` (
        `id` text PRIMARY KEY NOT NULL,
        `name` text NOT NULL
);

[βœ“] Changes applied

I connected to the new database and table and manually seeded two rows of data just to make sure (tested both with and without data)

Turso web ui view:

image

TablePlus view:

image

drizzle-kit introspect output:

> ❯ npx drizzle-kit introspect
drizzle-kit: v0.22.6
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file '.../drizzle.config.ts'
Pulling from ['public'] list of schemas

[βœ“] 0 tables fetched
[βœ“] 0 columns fetched
[βœ“] 0 indexes fetched
[βœ“] 0 foreign keys fetched

[βœ“] Your SQL migration file ➜ drizzle/0000_true_the_call.sql πŸš€
[βœ“] You schema file is ready ➜ drizzle/schema.ts πŸš€
[βœ“] You relations file is ready ➜ drizzle/relations.ts πŸš€

Since the introspection isn't working correctly, subsequent runs of drizzle-kit push will fail because it will attempt to create the table again.

npx drizzle-kit push
drizzle-kit: v0.22.6
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file '.../drizzle.config.ts'
[βœ“] Pulling schema from database...
 Warning  You are about to execute current statements:

CREATE TABLE `untitled_table_1` (
        `id` text PRIMARY KEY NOT NULL,
        `name` text NOT NULL
);

LibsqlError: SQL_INPUT_ERROR: SQL input error: table `untitled_table_1` already exists (at offset 13)
    at mapHranaError (.../node_modules/@libsql/client/lib-esm/hrana.js:262:16)
    at HttpClient.execute (.../node_modules/@libsql/client/lib-esm/http.js:80:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.run (.../drizzle-kit/bin.cjs:119857:15)
    at async sqlitePush (.../node_modules/drizzle-kit/bin.cjs:122665:13)
    at async _Command.<anonymous> (.../node_modules/drizzle-kit/bin.cjs:129712:7) {
  code: 'SQL_INPUT_ERROR',
  rawCode: undefined,
  [cause]: [ResponseError: SQL input error: table `untitled_table_1` already exists (at offset 13)] {
    code: 'SQL_INPUT_ERROR',
    proto: {
      message: 'SQL input error: table `untitled_table_1` already exists (at offset 13)',
      code: 'SQL_INPUT_ERROR'
    }
  }

I'm using @libsql/client v0.6.2 if that is relevant.

Expected behavior

No response

Environment & setup

No response