drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
290 stars 17 forks source link

`drizzle-kit push` does not work for schema other than default (`public`) #533

Closed adriannsemb closed 1 month ago

adriannsemb commented 1 month ago

When running having a pgSchema e.g. test, the database is not synced when running drizzle-kit push.

using schema

// src/drizzle/schema.ts
import { pgSchema, serial, text, varchar } from "drizzle-orm/pg-core";

const SCHEMA_NAME = "test";

export const appSchema = pgSchema(SCHEMA_NAME);

export const usersTable = appSchema.table("users", {
  id: serial("id").primaryKey(),
  fullName: text("full_name"),
  phone: varchar("phone", { length: 256 }),
});

output

No config path provided, using default 'drizzle.config.ts'
Reading config file '<repo_root>e/drizzle.config.ts'
Using 'postgres' driver for database querying
[✓] Pulling schema from database...
[i] No changes detected

No changes in the database e.g. when using drizzle-kit studio / running logging in and running \dn.

I would expect drizzle to create the schema and the tables for this schema. e.g.:

CREATE SCHEMA IF NOT EXISTS "test";
CREATE TABLE IF NOT EXISTS "test"."users" (
        "id" serial PRIMARY KEY NOT NULL,
        "full_name" text,
        "phone" varchar(256)
);

using default schema (public)

However, when using the default public schema, it works:

// src/drizzle/schema.ts
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";

export const usersTable1 = pgTable("users", {
  id: serial("id").primaryKey(),
  fullName: text("full_name"),
  phone: varchar("phone", { length: 256 }),
});

output

No config path provided, using default 'drizzle.config.ts'
Reading config file '<repo_root>/drizzle.config.ts'
Using 'postgres' driver for database querying
[✓] Pulling schema from database...

 Warning  You are about to execute current statements:

CREATE TABLE IF NOT EXISTS "users" (
        "id" serial PRIMARY KEY NOT NULL,
        "full_name" text,
        "phone" varchar(256)
);

[✓] Changes applied

Now I see the changes in the database e.g. when using drizzle-kit studio.

adriannsemb commented 1 month ago

Seems I wasn't using schemaFilter in drizzle.config.ts. Now it works as expected.

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schemaFilter: ["test"],
  // ...
});