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
24.2k stars 617 forks source link

[BUG]: SQLite adding a `primaryKey()` constraint #2741

Open hyunbinseo opened 3 months ago

hyunbinseo commented 3 months ago

What version of drizzle-orm are you using?

0.32.1

What version of drizzle-kit are you using?

0.23.1

Describe the Bug

Initial schema:

export const table = sqliteTable('table', {
  id: integer('id').unique().notNull(),
});
CREATE TABLE `table` (
  `id` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `table_id_unique` ON `table` (`id`);

(Works) Dropping the unique constraint:

export const table = sqliteTable('table', {
  id: integer('id').notNull(),
});
DROP INDEX IF EXISTS `table_id_unique`;

(Does not work) Adding a primary key constraint:

export const table = sqliteTable('table', {
  id: integer('id').primaryKey().notNull(),
});

No schema changes, nothing to migrate 😴

Expected behavior

drizzle-kit generate should probably generate a comment similar to this:

/*
 SQLite does not support "Drop not null from column" out of the box, we do not generate automatic migration for that, so it has to be done manually
 Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
                  https://www.sqlite.org/lang_altertable.html
                  https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3

 Due to that we don't generate migration automatically and it has to be done manually
*/

unique() ➡️ primaryKey() migration was needed because of the following issue's workaround:

Environment & setup

No response

hyunbinseo commented 3 months ago

This should have been posted in the drizzle-kit-mirror repository.

Could someone transfer this?