Skip to content

[BUG]: drizzle-kit pull in v1.0.0-beta.20 fails on fresh Nile DB with invalid internal value for Enum #5583

@MSGunaratne

Description

@MSGunaratne

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

1.0.0-beta.20

What version of drizzle-kit are you using?

1.0.0-beta.20

Other packages

No response

Describe the Bug

I am using Drizzle ORM v1 beta with NileDB and drizzle-kit pull fails during introspection on a fresh database.

Environment:
framework: Nextjs 14 Monorepo
language: Typescript (v.5.9.3)
runtime: Node 20.x
database: NileDB / Postgres
command: npx drizzle-kit pull

Config:
drizzle.config.ts

import { loadEnvConfig } from '@next/env';

loadEnvConfig(process.cwd());

import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  out: './drizzle',
  schema: [
    './src/server/modules/**/schema.ts',
    './src/server/modules/**/*.schema.ts',
    './src/server/modules/**/enums.ts',
    './src/server/db/enums.ts',
    './src/server/db/relations.ts',
  ],
  dialect: 'postgresql',
  casing: 'snake_case',
  dbCredentials: {
    url: process.env.NILEDB_URL!,
  },
  // Nile tables live in public and users schemas.
  schemaFilter: ['public', 'users'],
  extensionsFilters: ['postgis'],
});

src\server\db\index.ts

import { Pool } from 'pg';
import { drizzle } from 'drizzle-orm/node-postgres';

import { fullSchema } from './schema';
import { relations } from './relations';

const pool = new Pool({
  connectionString: process.env.NILEDB_URL!,
  max: 10, // Maximum connections in pool
  idleTimeoutMillis: 30000, //  30s
  connectionTimeoutMillis: 5000, //  5s
});

pool.on('error', (err) => {
  console.error('Unexpected error on idle client:', err);
});

export const db = drizzle({
  client: pool,
  relations,
  schema: fullSchema,
  casing: 'snake_case',
});

Expected:

  • drizzle-kit pull should introspect the database and generate migration sql and json files.
  • a schema file for nile built-in tenant and tenant_user tables and a relation file were also getting generated before the beta branch

Actual:
It fails immediately during introspection, before any tables are fetched:
invalid internal value for enum: 2

PS C:\Users\...\project-name> npx drizzle-kit pull
No config path provided, using default 'drizzle.config.ts'
Reading config file 'C:\Users\...\project-name\drizzle.config.ts'
Using 'pg' driver for database querying
[⣷] 0 tables fetching
[⣷] 0 columns fetching
[⣷] 0 enums fetching
[⣷] 0 indexes fetching
[⣷] 0 foreign keys fetching
[⣷] 0 policies fetching
[⣷] 0 check constraints fetching
[⣷] 0 views fetching
[✗] Error during introspection:
invalid internal value for enum: 2
Error: invalid internal value for enum: 2
    at C:\Users\...\project-name\node_modules\drizzle-kit\bin.cjs:233397:12
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.query (C:\Users\...\project-name\node_modules\drizzle-kit\bin.cjs:233392:13)
    at async Promise.all (index 3)
    at async fromDatabase$3 (C:\Users\...\project-name\node_modules\drizzle-kit\bin.cjs:237829:56)
    at async fromDatabaseForDrizzle$3 (C:\Users\...\project-name\node_modules\drizzle-kit\bin.cjs:238576:15)

Notes:

This happens on a fresh test database, and also on my existing production database.
My app Enums are string-backed TypeScript Enums.
The database contains Nile built-in schemas/tables in public and users, plus app tables in public.

Debug steps tried:

  • I deleted my node modules and did fresh install, the error persists
  • I simplified the drizzle config to the minimum required Nile setup and that didn't solve it
  • Finally used previously pulled files from before the beta migration, used drizzle-kit up to update to the new format and then ran drizzle-kit generate for my app's schemas and successfully ran drizzle-kit migrate
  • After that first successful migration, no new migrations or pushes worked and i have to create a new db for each schema change

Minimal reproduction:
Run npx drizzle-kit pull against a fresh Nile database with the config above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions