drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
289 stars 17 forks source link

[SQLite] Cannot push schema changes with `drizzle-kit` 0.23.0 #500

Open JoshStwrt opened 3 months ago

JoshStwrt commented 3 months ago

I get the following error when trying to push schema changes (drizzle-kit push)

TypeError: This statement does not return data. Use run() instead
    at Object.query (/****/node_modules/.pnpm/drizzle-kit@0.23.0/node_modules/drizzle-kit/bin.cjs:121780:54)
    at sqlitePush (/****/node_modules/.pnpm/drizzle-kit@0.23.0/node_modules/drizzle-kit/bin.cjs:124445:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _Command.<anonymous> (/****/node_modules/.pnpm/drizzle-kit@0.23.0/node_modules/drizzle-kit/bin.cjs:131629:7)

user.ts

import { sqliteTable, text } from "drizzle-orm/sqlite-core";

export const userTable = sqliteTable("user", {
    id: text("id").notNull().primaryKey(),
});

drizzle.config.ts

import { defineConfig } from "drizzle-kit";

export default defineConfig({
    dialect: "sqlite",
    dbCredentials: {
        url: process.env.DB_PATH,
    },
    schema: ["./user.ts"],
    strict: true,
    verbose: true,
});

Versions

drizzle-kit: 0.23.0 node: 22.4.1

DewinU commented 3 months ago

Having the same issue here, both on windows and linux, figure a "workaround" changing query to run directly in the package

 if (statementsToExecute.length === 0) {
          (0, import_hanji11.render)(`
[${source_default.blue("i")}] No changes detected`);
        } else {
          if (!("driver" in credentials2)) {
            await db2.query("begin");  //db2.run("begin")
            try {
              for (const dStmnt of statementsToExecute) {
                await db2.query(dStmnt); //db2.run(dStmnt)
              }
              await db2.query("commit"); //db2.run("commit"))
            } catch (e2) {
              console.error(e2);
              await db2.query("rollback"); //db2.run("rollback")
              process.exit(1);
            }
          } else if (credentials2.driver === "turso") {
            await db2.batch(statementsToExecute.map((it) => ({ query: it })));
          }
          (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
        }

Working as expected on Drizzle-Kit 0.22.8, guessing is because they are using run() instead of query()

if (statementsToExecute.length === 0) {
          (0, import_hanji11.render)(`
[${source_default.blue("i")}] No changes detected`);
        } else {
          for (const dStmnt of statementsToExecute) {
            await db2.run(dStmnt);
          }
          (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
        }
      }

There's also another issue related to this that was open in the drizzle orm repository instead

Bouchtaoui commented 3 months ago

Exactly the same issue. But somehow I can migrate and have my database tables created. So I use migrate instead of push, hope it works for you too.

steebchen commented 1 month ago

Also having this issue, unfortunately push is completely unusable in my case

AsemK commented 1 month ago

also have the same issue on 0.24.2. works on 0.22.8 though.