drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

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

Open jennnx opened this issue 2 years ago • 1 comments

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

  • Adding constraints like autoincrements to existing columns
  • Changing existing column type

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

jennnx avatar Dec 27 '23 00:12 jennnx

I'm facing an issue like that using [email protected] + [email protected].

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" }),
});

igorbrasileiro avatar May 21 '24 13:05 igorbrasileiro

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 avatar Jun 27 '24 23:06 Blanen

2 way to solve this:

1.Stop adding breakpoints for comments.
2. 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?

Blanen avatar Jun 27 '24 23:06 Blanen

Facing this issue too on the libsql driver. Deleting the comments fixed the issue.

mastorm avatar Sep 20 '24 18:09 mastorm

These comments no longer exist in the latest version.

L-Mario564 avatar Oct 17 '24 18:10 L-Mario564