Cannot push postgres

I am initiating the db schema useing drizzlekit, but for some reason I can only push once and the second time it throws an error this is me running "pnpm drizzle-kit push" for the first time
root@f2771f2cc095:/app# pnpm drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/app/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 "session" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"expires_at" timestamp with time zone NOT NULL,
"active" boolean DEFAULT true NOT NULL
);

CREATE TABLE IF NOT EXISTS "user" (
"id" text PRIMARY KEY NOT NULL,
"username" text NOT NULL,
"first_name" text NOT NULL,
"last_name" text NOT NULL,
"email" text NOT NULL,
"profile_picture" text,
"is_verified" boolean DEFAULT false NOT NULL,
"is_admin" boolean DEFAULT false NOT NULL,
CONSTRAINT "user_username_unique" UNIQUE("username"),
CONSTRAINT "user_email_unique" UNIQUE("email")
);

DO $$ BEGIN
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;


[✓] Changes applied
root@f2771f2cc095:/app# pnpm drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/app/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 "session" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"expires_at" timestamp with time zone NOT NULL,
"active" boolean DEFAULT true NOT NULL
);

CREATE TABLE IF NOT EXISTS "user" (
"id" text PRIMARY KEY NOT NULL,
"username" text NOT NULL,
"first_name" text NOT NULL,
"last_name" text NOT NULL,
"email" text NOT NULL,
"profile_picture" text,
"is_verified" boolean DEFAULT false NOT NULL,
"is_admin" boolean DEFAULT false NOT NULL,
CONSTRAINT "user_username_unique" UNIQUE("username"),
CONSTRAINT "user_email_unique" UNIQUE("email")
);

DO $$ BEGIN
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;


[✓] Changes applied
12 Replies
MahmoodKhalil
MahmoodKhalil2mo ago
this is me running "pnpm drizzle-kit push" directly after the first time
root@f2771f2cc095:/app# pnpm drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/app/drizzle.config.ts'
Using 'postgres' driver for database querying
[⢿] Pulling schema from database...
/app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:18976
const onUpdate = fk4.update_rule.toLowerCase();
^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at /app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:18976:48
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.16.0
root@f2771f2cc095:/app# pnpm drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/app/drizzle.config.ts'
Using 'postgres' driver for database querying
[⢿] Pulling schema from database...
/app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:18976
const onUpdate = fk4.update_rule.toLowerCase();
^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at /app/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:18976:48
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.16.0
doesnt anyone know what this means? "TypeError: Cannot read properties of undefined (reading 'toLowerCase')" Hello, can someone please assist with this bug
Mario564
Mario5642mo ago
@MahmoodKhalil Hi there, this is a known issue in Kit. Could you provide your schema so I could try reproducing the bug?
MahmoodKhalil
MahmoodKhalil2mo ago
Thanks a lot in advanced this is the schema.ts
import { pgTable, boolean, text, timestamp, serial } from "drizzle-orm/pg-core";

export const userTable = pgTable("user", {
id: text("id").primaryKey(),
username: text("username").notNull().unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
profilePicture: text("profile_picture"),
is_verified: boolean("is_verified").notNull().default(false),
is_admin: boolean("is_admin").notNull().default(false),
});

export const sessionTable = pgTable("session", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => userTable.id),
expiresAt: timestamp("expires_at", {
withTimezone: true,
mode: "date",
}).notNull(),
active: boolean("active").notNull().default(true),
});
import { pgTable, boolean, text, timestamp, serial } from "drizzle-orm/pg-core";

export const userTable = pgTable("user", {
id: text("id").primaryKey(),
username: text("username").notNull().unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
profilePicture: text("profile_picture"),
is_verified: boolean("is_verified").notNull().default(false),
is_admin: boolean("is_admin").notNull().default(false),
});

export const sessionTable = pgTable("session", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => userTable.id),
expiresAt: timestamp("expires_at", {
withTimezone: true,
mode: "date",
}).notNull(),
active: boolean("active").notNull().default(true),
});
MahmoodKhalil
MahmoodKhalil2mo ago
for context, I am using lucia and I got it from here https://lucia-auth.com/database/drizzle#postgresql
Lucia
Drizzle ORM
Lucia is an open source auth library that abstracts away the complexity of handling sessions.
Mario564
Mario5642mo ago
Okay, thanks Could you also tell me what version of ORM and Kit you're using? Pretty sure this affects latest but want to make sure
MahmoodKhalil
MahmoodKhalil2mo ago
I am using the latest "drizzle-kit": "^0.24.1", "drizzle-orm": "^0.33.0", @Mario564 sorry for the trouble, I think I fixed it
MahmoodKhalil
MahmoodKhalil2mo ago
I was connecting to the db using this method https://orm.drizzle.team/docs/get-started-postgresql#supabase
Drizzle ORM - PostgreSQL
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
MahmoodKhalil
MahmoodKhalil2mo ago
this seems to have issues at this point When I connected the way mentioned here, it works just fine @Mario564 let me know if you are still investigating and need help reproducing, I can make a quick repo if that would help Personally my issue is fixed and I dont need any help
Mario564
Mario5642mo ago
Interesting, seems to be an issue specific to Supabase then It would be very helpful if you could provide a minimal repo to reproduce the bug
MahmoodKhalil
MahmoodKhalil2mo ago
@Mario564 https://github.com/MahmoodKhalil57/drizzlekiterror 1.
git clone https://github.com/MahmoodKhalil57/drizzlekiterror.git
git clone https://github.com/MahmoodKhalil57/drizzlekiterror.git
2. add .env
DATABASE_URL="postgresql://postgres.[SECRET]/postgres"
DATABASE_URL="postgresql://postgres.[SECRET]/postgres"
3.
pnpm i
pnpm i
4.
pnpm drizzle-kit push
pnpm drizzle-kit push
5. then again
pnpm drizzle-kit push
pnpm drizzle-kit push
second time should throw an error
GitHub
GitHub - MahmoodKhalil57/drizzlekiterror
Contribute to MahmoodKhalil57/drizzlekiterror development by creating an account on GitHub.
Mario564
Mario5642mo ago
This will likely prove to be very useful. Thanks!
Shuvi ☁ 🪽
Shuvi ☁ 🪽2mo ago
same issue here, in my case it's throwing an error about cascading instead
PostgresError: cannot drop sequence "truncated" because other objects depend on it
at ErrorResponse ([email protected]/node_modules/postgres/src/connection.js:788:26)
at handle ([email protected]/node_modules/postgres/src/connection.js:474:6)
at Socket.data ([email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:545:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
at Readable.push (node:internal/streams/readable:375:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '2BP01',
detail: 'default value for column id of table "truncated" depends on sequence "truncated"',
hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
file: 'dependency.c',
line: '1204',
routine: 'reportDependentObjects'
}
PostgresError: cannot drop sequence "truncated" because other objects depend on it
at ErrorResponse ([email protected]/node_modules/postgres/src/connection.js:788:26)
at handle ([email protected]/node_modules/postgres/src/connection.js:474:6)
at Socket.data ([email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:545:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
at Readable.push (node:internal/streams/readable:375:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '2BP01',
detail: 'default value for column id of table "truncated" depends on sequence "truncated"',
hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
file: 'dependency.c',
line: '1204',
routine: 'reportDependentObjects'
}
export const userProfiles = createTable(
"user_profile",
{
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 36 })
.references(() => users.id, { onDelete: "cascade" })
.unique(),
},
(table) => ({
userIdIdx: uniqueIndex("user_profile_userId_idx").on(table.userId),
}),
);
export const userProfiles = createTable(
"user_profile",
{
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 36 })
.references(() => users.id, { onDelete: "cascade" })
.unique(),
},
(table) => ({
userIdIdx: uniqueIndex("user_profile_userId_idx").on(table.userId),
}),
);
Want results from more Discord servers?
Add your server