drizzle-team / drizzle-team/drizzle-orm

[BUG]: Non-default schemas in Postgres lead to incorrect sequence alterations

Open
#4,969 0 comments 0 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta db/postgres
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.44.6

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

0.31.5

### Other packages

_No response_

### Describe the Bug

**What is the undesired behavior?**

When using a non-default schema in Postgres and the drizzle-kit `push` command, incorrect sequence changes will be presented and applied.

**What are the steps to reproduce it?**

Use a `drizzle.config.ts` that allows your custom schema:

```js
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
dialect: 'postgresql',
schema: ['./src/**/*.sql.ts'],
out: './migrations',
schemaFilter: ['public', 'my-schema'],
dbCredentials: {
url: process.env.DATABASE_URL
},
verbose: true,
strict: true
});
```

Create a table using the non-default schema, like so:

```js
import { pgSchema, text, integer } from 'drizzle-orm/pg-core';

export const schema = pgSchema('my-schema');

export const todo = schema.table('todo', {
id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
title: text('title').notNull(),
description: text('description')
});
```

Run the `drizzle-kit push` command... Your table should be created.

Run the `drizzle-kit push` command again, notice it tries to remove your sequence, and will potentially try to make other changes related to the sequence (in my example below it also misses the cache property).

Image

**What is the desired result?**

Only valid changes should be applied.

**PR**

I traced this issue to improper handling of the fully-qualified column name being returned from `getColumnsInfoQuery` and updated that query to normalize the name so that existing code works correctly.

PR is open here: #4966

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.