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
22.13k stars 514 forks source link

[BUG]: Incorrect statement breakpoints cause libsql migrations to fail with SQL_NO_STATEMENT error #1709

Open jennnx opened 7 months ago

jennnx commented 7 months ago

What version of drizzle-orm are you using?

0.29.1

What version of drizzle-kit are you using?

0.20.7

Describe the Bug

Generating migration files for libsql will sometimes produce incorrect -->statement-breakpoints.

For example

The generated migration files will produce a

Error performing migration:  LibsqlError: SQL_NO_STATEMENT: SQL string does not contain any statement

error when applying a migration with drizzle-orm/libsql/migrator.

Screenshot 2023-12-26 at 4 25 21 PM

Workaround:

Manually deleting the two statement breakpoints highlighted above fixes the issue.

[Note]

This bug forced me to read the autogenerated comments, which informed me that migrations for these constraints will be have to applied manually (by cloning the table, renaming it, dropping it, and renaming again). I think having an explicit warning during drizzle-kit generate:sqlite would be helpful!

Expected behavior

Migrations should apply without error

Environment & setup

No response

igorbrasileiro commented 2 months ago

I'm facing an issue like that using drizzle-orm@0.30.10 + drizzle-kit@0.21.2.

schema before:

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

export const users = sqliteTable("users", {
  id: integer("id").primaryKey({ autoIncrement: true }).notNull(),
  fullName: text("fullName").notNull(),
});

schema after:

export const users = sqliteTable("users", {
  id: integer("id").primaryKey({ autoIncrement: true }).notNull(),
  fullName: text("fullName").notNull(),
  birthday: integer("birthday", { mode: "timestamp" }),
});
Blanen commented 1 month ago

Yes.

Same issue. It has put a breakpoint solely for a comment and as a such an empty statement.

Weird thing is that I tried looking in to where the issue is or even what code creates that comment but couldn't find it.

Blanen commented 1 month ago

2 way to solve this:

1.Stop adding breakpoints for comments.

  1. Add to migration code to skip functionally empty sql

1 is obviously highly preferred.

If anyone could point me in the right direction I can do the work. I check this repo and the drizzle-kit-mirror repo but its in neither?