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.72k stars 653 forks source link

[BUG]: `drizzle-kit push` always shows columns with custom types as changed even tho the type didn't change #3047

Open shreyassanthu77 opened 1 month ago

shreyassanthu77 commented 1 month ago

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

0.24.2

Describe the Bug

So I have the following schema file

import { sqliteTable, text } from "drizzle-orm/sqlite-core";
import { f32Blob } from "./blob.ts";
//
export const example = sqliteTable("example", {
  id: text("id").primaryKey(),
  blob: f32Blob("blob", {
    length: 10,
  }),
});

and here's the blob.ts file

import { Buffer } from "node:buffer";
import { customType } from "drizzle-orm/sqlite-core";

export const f32Blob = customType<{
  data: number[];
  config: {
    length: number;
  };
  configRequired: true;
}>({
  dataType(conf) {
    return `F32_BLOB(${conf.length})`;
  },
  fromDriver(value: Buffer) {
    const fArr = new Float32Array(new Uint8Array(value).buffer);
    return Array.from(fArr);
  },

  toDriver(value) {
    return Buffer.from(new Float32Array(value).buffer);
  },
});

the drizzle config file

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./drizzle/schema.ts",
  dialect: "sqlite",
  driver: "turso",
  dbCredentials: {
    url: "http://127.0.0.1:6969",
    authToken: "turso-token",
  },
  strict: true,
  verbose: true,
});

when i run drizzle-kit push for the first time with an empty libsql db

image

when i run drizzle-kit push just after the first one with 0 changes to the schema file or the blob.ts whatsoever

image

Expected behavior

well, the expected behaviour is it should not happen. This is just an example but in a real production app with a lot of relations, all the tables that depend on this table are being renamed and copied for no reason at all. This is bad and causes foriegn key errors sometimes which is frustrating and now i am just manually running my migrations but would be very helpful if i didn't have to.

btw Love the project and very grateful for all the work :)

Environment & setup

shreyassanthu77 commented 1 month ago

another kinda related issue

so libsql has a built in vector extension and has a way to create an index on a vector field eg

CREATE INDEX test_idx ON example (libsql_vector_idx(blob));

also there's no way (that i know of) to write this with drizzle

but when i run drizzle-kit push again it asks to drop the index and i don't think there's a way to tell drizzle kit to ignore just that index/table image