Skip to content

[BUG]: drizzle-kit push attempts to drop policies in excluded schemas (e.g. cron) despite schemaFilter: ["public"] #5329

@SennaSanzo

Description

@SennaSanzo

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.13-f728631

What version of drizzle-kit are you using?

1.0.0-beta.13-f728631

Other packages

No response

Describe the Bug

What is the undesired behavior?

When running drizzle-kit push, the tool attempts to drop or modify database objects (specifically policies on cron.job) that reside in schemas explicitly excluded by the schemaFilter configuration.

Even with schemaFilter: ["public"] configured in [drizzle.config.ts], drizzle-kit introspects the cron schema (created by the pg_cron extension) and generates SQL to drop its policies. This results in a permission error because the user does not own the extension-managed objects.

Note 1: Although the documentation states that the default schemaFilter is ["public"], I observed different results when explicitly setting it versus omitting it, suggesting the default might not be applied as expected in this version.
Note 2: The execution halts immediately at the drop policy error on the cron schema. Therefore, I cannot confirm whether other schemas present in the database would also be incorrectly targeted, but it is possible that the issue extends to them as well.

Additionally, attempting to use extensionsFilters as a workaround fails because:

  1. It seems to be ignored or insufficient to prevent this introspection.
  2. The TypeScript types for extensionsFilters are overly restrictive (only allowing "postgis" in our version), creating type errors.

What are the steps to reproduce it?

  1. Use a PostgreSQL database (e.g., Supabase) with the pg_cron extension enabled (which creates a cron schema and default policies).
  2. Configure [drizzle.config.ts] to only manage the public schema:
  export default defineConfig({
    schemaFilter: ["public"],
    // ... other config
  });
  1. Run drizzle-kit push.
  2. Observe that drizzle-kit generates SQL statements targeting the cron schema, such as:
DROP POLICY "cron_job_policy" ON "cron"."job";
  1. The command fails with: query error: must be owner of relation job.

What is the desired result?

drizzle-kit should strictly respect the schemaFilter configuration. If schemaFilter is set to ["public"], no other schemas (like cron, auth, storage, etc.) should be introspected, and no SQL should be generated for them, regardless of whether they contain extensions or not.

Environment & Configuration

What database engine are you using? Are you using a specific cloud provider? Which one?
PostgreSQL via Supabase.

Do you think this bug pertains to a specific database driver? Which one?
Likely specific to drizzle-kit's introspection logic on PostgreSQL when extensions are present. We are using postgres (postgres.js) or pg driver, but this occurs at the drizzle-kit push level.

Are you working in a monorepo?
Yes, referencing a shared config in a packages/db workspace.

If this is a bug related to types: What Typescript version are you using?
TypeScript 5.x.

Configuration (drizzle.config.ts):

import { defineConfig } from "drizzle-kit";
export default defineConfig({
  out: "./src/drizzle/migrations",
  schema: "./src/drizzle/schema.ts",
  schemaFilter: ["public"],
  // Attempted workaround (failed primarily due to types and lack of effect):
  // extensionsFilters: ["postgis", "pg_cron"], 
  strict: true,
  verbose: true,
  dialect: "postgresql",
  // ... credentials
});

Error Log:

DROP POLICY "cron_job_policy" ON "cron"."job";
--> query error: must be owner of relation job

Metadata

Metadata

Assignees

No one assigned

    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