drizzle-team / drizzle-team/drizzle-orm

[BUG]: Drizzle Studio Error with PostGIS and Relations in Bun Environment: Symbol(drizzle:Schema)

Open
#4,072 0 comments 0 reactions 0 assignees View on GitHub
bug drizzle/studio
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.39.1

### What version of `drizzle-kit` are you using?

0.30.4

### Other packages

_No response_

### Describe the Bug

# Drizzle Studio Error with PostGIS and Relations in Bun Environment

## Package Versions
- `drizzle-orm`: 0.39.1
- `drizzle-kit`: 0.30.4
- TypeScript: ^5.7.3
- Bun runtime (@types/bun: ^1.2.2)

## Bug Description

### Undesired Behavior
When running `bunx drizzle-kit studio`, getting the following error:
```
TypeError: Cannot read properties of undefined (reading 'Symbol(drizzle:Schema)')
at getTableUniqueName (/[...]/node_modules/src/table.ts:149:12)
at extractTablesRelationalConfig (/[...]/node_modules/src/relations.ts:472:19)
at prepareServer ([...]/node_modules/drizzle-kit/bin.cjs:76977:86)
```

### Steps to Reproduce

1. Set up a PostgreSQL database with PostGIS extension
2. Create schema with relations and geometry type columns:
```typescript
// Example table with geometry
export const location = pgTable('location', {
id: uuid('id').defaultRandom().primaryKey().notNull(),
// ... other fields
geom: geometry('geom', { type: 'point', srid: 4326 }),
})

// Relations
export const locationRelations = relations(location, ({ one }) => ({
organization: one(organization, {
fields: [location.organizationId],
references: [organization.id]
})
}))
```
3. Successfully run migrations using `drizzle-kit generate` and apply them
4. Try to launch Drizzle Studio using `drizzle-kit studio`

### Project Context
- Using Bun runtime
- PostgreSQL with PostGIS extension
- Project structure uses module-based schema organization with separate files for tables and relations

### Configuration
```typescript
// drizzle.config.ts
export default defineConfig({
out: './drizzle',
schema: './src/schema/index.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DEV_DB_URL!,
},
});

// src/index.ts
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/bun-sql';
import { SQL } from 'bun';
import * as schema from './schema';

export const client = new SQL(process.env.DATABASE_URL!);
export const db = drizzle({ client, schema });
```

### Analysis

#### Potential Issue Sources
1. The error occurs in the relations extraction process, suggesting a potential issue with how Drizzle Studio handles:
- Custom column types (geometry from PostGIS)
- Relations in a modular schema setup
- Schema symbol initialization when using Bun's SQL driver

2. The error specifically mentions `Symbol(drizzle:Schema)` being undefined, which could indicate:
- A mismatch between how the schema is initialized in the main app vs how Studio tries to read it
- Potential incompatibility between Bun's SQL driver and Studio's schema parsing
- Issues with how relations are processed when custom types are involved

### Desired Result
Drizzle Studio should successfully launch and be able to read the schema with its relations and custom PostGIS types.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.