[BUG]: Undefined properties when using drizzle-kit push
What version of drizzle-orm are you using?
0.36.0
What version of drizzle-kit are you using?
0.27.1
Describe the Bug
When using drizzle-kit push I'm receiving the following error:
TypeError: Cannot read properties of undefined (reading 'isRLSEnabled')
My client setup:
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "@/lib/database/schema";
export const db = drizzle(process.env.DATABASE_URL!, { schema: schema });
Drizzle config:
import dotenv from "dotenv";
import { defineConfig } from "drizzle-kit";
dotenv.config({ path: ".env.local" });
export default defineConfig({
dialect: "postgresql",
schema: "./lib/database/schema.ts",
out: "./lib/database/migrations",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
strict: true,
});
Expected behavior
No response
Environment & setup
Development
Same Error for me, using supabase
exact same thing here, seems like some null checks are missing in applyPgSnapshotsDiff
exactly the same thing for me too
the same thing for me too
same problem occurring for me as well. not sure what's up with this; a recent migration worked out alright--i'm using xata postgres
I'm having the same error
i did something really weird...so i have multiple schemas defined in my schema.ts and i removed all of them except one. did npx drizzle-kit generate and then npx drizzle-kit migrate. repeated the process by re-adding my schemas and somehow everything worked...not sure what's up with that though.
same error for me with postgres
same
- same package drizzle & drizzle-kit versions
- getting same error when running
drizzle-kit generate - postgres
I have the same, for postgres generate.
Update: Tried with 0.26.2, tells me to upgrade...
This version of drizzle-kit is outdated Please update drizzle-kit package to the latest version 👍
I tried the "delete schema, generate, revert partially, generate again, then use latest schema, and generate one more time" and it worked somehow
a folder with 'bad' migrations was my issue. deleted that and all's well now🙌🏽
same
It seems there is a missing nullcheck and adding an optional chaining operator in drizzle-kit code fixes the issue. I cannot assure it will works if you avec RLS defined, but if you don't you should be able to generate migrations correctly.
- Go to
node_modules/drizzle-kit/bin.cjs - Edit line 29886. Replace
if (table4.isRLSEnabled !== tableInPreviousState.isRLSEnabled) {
With
if (table4.isRLSEnabled !== tableInPreviousState?.isRLSEnabled) {
About the issue:
tableInPreviousState is known to be possibly undefined as line 29878 checks for it:
const policiesInPreviousState = tableInPreviousState ? Object.keys(tableInPreviousState.policies) : [];
There must be a type issue or misconfiguration somewhere that Typescript did not catch it at compile time.
pushing a fix in 30 mins
sorry for a long fix for this blocker
Just tested with drizzle-kit@rls-fix
Should be fixed there. Including in the latest now
tysm!