drizzle-team / drizzle-team/drizzle-orm
[BUG]: PgEnum does not work with Xata Postgres Beta (got unsupported statement [DO] on regular level)
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### 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. (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 `generate`and 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
```ts
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:
```ts
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
```sql
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',
);
```
Contributor guide
Assessment
This issue has not been assessed yet.