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.47k stars 642 forks source link

[BUG]: PgEnum does not work with Xata Postgres Beta (got unsupported statement [DO] on regular level) #2394

Open Dadangdut33 opened 5 months ago

Dadangdut33 commented 5 months ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

When using pgEnum, it won't work with xata when trying to push the schema because of this error

error: unsupported statement [DO] on regular level, see https://xata.io/sql-support for the support matrix
    at F:\Typescript\Personal Web\Personal-Web\node_modules\.pnpm\drizzle-kit@0.21.4\node_modules\drizzle-kit\bin.cjs:69429:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.query (F:\Typescript\Personal Web\Personal-Web\node_modules\.pnpm\drizzle-kit@0.21.4\node_modules\drizzle-kit\bin.cjs:111366:26)
    at async pgPush (F:\Typescript\Personal Web\Personal-Web\node_modules\.pnpm\drizzle-kit@0.21.4\node_modules\drizzle-kit\bin.cjs:114524:13)
    at async Command.<anonymous> (F:\Typescript\Personal Web\Personal-Web\node_modules\.pnpm\drizzle-kit@0.21.4\node_modules\drizzle-kit\bin.cjs:121480:7) {
  length: 106,
  severity: undefined,
  code: undefined,
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: undefined,
  line: undefined,
  routine: undefined
}

is enum just not possible to be used when using the beta postgres from xata?

i tried using the raw query in the xata web playground using the sql code that you get from doing generateand it seems that enum actually works but i needed to remove the do statement and also the public in the type.

Expected behavior

i expect it to work without error. I have also tried my schema in local postgres and it works fine.

Environment & setup

Here is my drizzle config

import { env } from "@/lib/env.mjs";
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/lib/db/schema",
  out: "./drizzle/generated",
  dialect: "postgresql",
  dbCredentials: {
    url: (env.DATABASE_URL as string) ?? "",
  },
  verbose: true,
});

The enum usage example:

import { pgEnum } from "drizzle-orm/pg-core";

export const VisibilityOption = ["draft", "private", "published"] as const;
export type VisibilityType = (typeof VisibilityOption)[number];
export const visibilityEnum = pgEnum("visibility", VisibilityOption);

export const M_Blog = pgTable("blog", {
  id: uuid("id").defaultRandom().primaryKey(),
  description: text("description").notNull(),
  content: json("content").notNull(),
  visibility: visibilityEnum("visibility").default("draft"),
);

The verbose output

DO $$ BEGIN
 CREATE TYPE "public"."visibility" AS ENUM('draft', 'private', 'published');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "blog" (
        "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
        "description" text NOT NULL,
        "content" json NOT NULL,
        "visibility" "visibility" DEFAULT 'draft',
);
AndriiSherman commented 5 months ago

working on fixing it!