drizzle-team / drizzle-team/drizzle-orm
[BUG]: Generating migrations with tablesFilter deletes tables with a similar name
- 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.29.5
### What version of `drizzle-kit` are you using?
0.20.14
### Describe the Bug
I'm trying to use the same DB instance but separate brances with `tablesFilter`, so dev branches will have a `dev_` prefix and prod will have `prod_` prefix.
Here's my drizzle.config.ts:
```ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./src/db/schema.ts",
out: "./src/db/migrations",
tablesFilter: [`${process.env.POSTGRES_PREFIX}*`],
driver: "pg",
dbCredentials: {
connectionString: process.env.POSTGRES_URL,
},
verbose: true,
strict: true,
});
```
To make it work I use `drizzlekit generate:pg` with different POSTGRES_PREFIX env var, once for dev and once for prod.
The command I ran were:
```sh
POSTGRES_PREFIX=dev_ drizzle-kit generate:pg;
POSTGRES_PREFIX=prod_ drizzle-kit generate:pg;
```
When generating the migration for dev it everything was fine, but when I then tried to generate the migration for prod the cli asked me if the a table (in this case `prod_items`) was new or a rename of `dev_items`. I chose that it is a new table and the migration that was created is:
```sql
CREATE TABLE IF NOT EXISTS "prod_items" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(256) NOT NULL,
"checked" boolean DEFAULT false NOT NULL,
"recurring" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
DROP TABLE "dev_items";--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "name_idx" ON "prod_items" ("name");
```
### Expected behavior
The expected behavior is that tables with a different prefix would not be deleted when generating migrations for another prefix (which could be an entirely different project).
### Environment & setup
I use Vercel's Postgres in a Next.js project.
This is the repo I'm using: https://github.com/dorshinar/shopshop
Contributor guide
Assessment
This issue has not been assessed yet.