Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Unhandled defaults when introspecting postgres db #1625

Closed
fvaldes33 opened this issue Dec 8, 2023 · 2 comments
Closed

[BUG]: Unhandled defaults when introspecting postgres db #1625

fvaldes33 opened this issue Dec 8, 2023 · 2 comments
Labels
bug Something isn't working drizzle/kit

Comments

@fvaldes33
Copy link

What version of drizzle-orm are you using?

0.29.1

What version of drizzle-kit are you using?

0.20.6

Describe the Bug

When running the introspect:pg command, some defaults are correctly wrapped in a sql tag while some others are not. To test this I have an almost untouched supabase instance running locally and also have multi schema set up in the drizzle config so that I can correctly pull in the auth schema since some of my tables are related to that auth.users table.

// bad default, should be wrapped in sql``
export const users = auth.table("users", {
  phone: text("phone").default(NULL::character varying),
})

// this one is right
export const workspaces = pgTable("workspaces", {
  id: uuid("id").default(sql`uuid_generate_v4()`).primaryKey().notNull(),
});

Same thing happens for some timestamp defaults.

Expected behavior

When running introspect, all defaults are correctly set or wrapped in the sql tag

Environment & setup

{
  "name": "@repo/database",
  "version": "0.0.0",
  "private": true,
  "main": "./src/index.ts",
  "scripts": {
    "db:generate": "drizzle-kit generate:pg",
    "db:introspect": "drizzle-kit introspect:pg",
    "db:push": "drizzle-kit push:pg"
  },
  "devDependencies": {
    "@repo/typescript-config": "workspace:*",
    "@types/node": "^20.10.4",
    "drizzle-kit": "^0.20.6",
    "typescript": "^5.3.3"
  },
  "dependencies": {
    "drizzle-orm": "^0.29.1",
    "postgres": "^3.4.3"
  }
}
import "dotenv/config";
import type { Config } from "drizzle-kit";

export default {
  schema: "./src/schema.ts",
  out: "./src",
  driver: "pg",
  dbCredentials: {
    connectionString: process.env.DATABASE_URL!,
  },
  introspect: {
    casing: "preserve",
  },
  schemaFilter: ["auth", "public"],
} satisfies Config;
@fvaldes33 fvaldes33 added the bug Something isn't working label Dec 8, 2023
@probablykasper
Copy link

For my MariaDB database, I noticed the migrations also have this issue:

CREATE TABLE `users` (
	`role` varchar(100) DEFAULT 'NULL'
);

Even though this is what's returned from SHOW CREATE TABLE users:

CREATE TABLE `users` (
  `role` varchar(100) DEFAULT NULL
)

@AndriiSherman
Copy link
Member

This should be fixed in drizzle-kit@0.24.1
If you still encounter this issue, please reopen the ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle/kit
Projects
None yet
Development

No branches or pull requests

4 participants