Trying to rename empty table from "user" to "users" w/ push

Building an app using T3 stack w/ Drizzle and PlanetScale(MySQL) Here's my current schema (at the bottom), I'm trying to rename "user" to "users" and my table is completely empty. When I run "db:push": "drizzle-kit push:mysql" I get
Is beesly_users table created or renamed from another table?
+ beesly_users create table
~ beesly_user › beesly_users rename table
Is beesly_users table created or renamed from another table?
+ beesly_users create table
~ beesly_user › beesly_users rename table
I've tried the second option to rename it and I get this back
~ beesly_user › beesly_users table will be renamed
--- all table conflicts resolved ---

TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
at /Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17175:51
at Array.map (<anonymous>)
at prepareDeleteCompositePrimaryKeyMySql (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17170:33)
at /Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17560:33
at Array.forEach (<anonymous>)
at applySnapshotsDiff (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17488:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async prepareSQL (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:15055:14)
at async prepareMySQLPush (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:14863:47)
at async Command.<anonymous> (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:63069:22)
[i] No changes detected
~ beesly_user › beesly_users table will be renamed
--- all table conflicts resolved ---

TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
at /Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17175:51
at Array.map (<anonymous>)
at prepareDeleteCompositePrimaryKeyMySql (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17170:33)
at /Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17560:33
at Array.forEach (<anonymous>)
at applySnapshotsDiff (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:17488:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async prepareSQL (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:15055:14)
at async prepareMySQLPush (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:14863:47)
at async Command.<anonymous> (/Users/jassi/Documents/Dev/booking-app/beesly/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:63069:22)
[i] No changes detected
No idea what is happening, since I'm working in development I don't mind deleting tables completely or wiping data from them frequently right now, so just curious, should I be handling this a different way? I generally thought if I did push that it was going to rebuild the entire db based off my current schema ? Full schema so far
export const createTable = mysqlTableCreator((name) => `beesly_${name}`);

export const users = createTable(
"user", // Tried to rename this to "users"
{
id: varchar("id", { length: 256 }).primaryKey(),
email: varchar("email", { length: 256 }).unique(),
username: varchar("username", { length: 256 }).unique(),
displayName: varchar("display_name", { length: 256 }),
userImage: varchar("user_image", { length: 2048 }),
onboarded: boolean("onboarded").default(false).notNull(),
stripeCustomerId: varchar("stripe_customer_id", { length: 256 }).unique(),
stripeSubscriptionId: varchar("stripe_subscription_id", {
length: 256,
}).unique(),
stripePriceId: varchar("stripe_price_id", { length: 256 }),
stripeCurrentPeriodEnd: timestamp("stripe_current_period_end"),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
},
(table) => ({
emailIndex: index("email_idx").on(table.email),
}),
);
export const createTable = mysqlTableCreator((name) => `beesly_${name}`);

export const users = createTable(
"user", // Tried to rename this to "users"
{
id: varchar("id", { length: 256 }).primaryKey(),
email: varchar("email", { length: 256 }).unique(),
username: varchar("username", { length: 256 }).unique(),
displayName: varchar("display_name", { length: 256 }),
userImage: varchar("user_image", { length: 2048 }),
onboarded: boolean("onboarded").default(false).notNull(),
stripeCustomerId: varchar("stripe_customer_id", { length: 256 }).unique(),
stripeSubscriptionId: varchar("stripe_subscription_id", {
length: 256,
}).unique(),
stripePriceId: varchar("stripe_price_id", { length: 256 }),
stripeCurrentPeriodEnd: timestamp("stripe_current_period_end"),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
},
(table) => ({
emailIndex: index("email_idx").on(table.email),
}),
);
1 Reply
hkfi
hkfi11mo ago
Facing the same issue here, super frustrating... It seems to be an issue with setting columns notNull(), unique(), or primaryKey(). I managed to rename by first removing those properties from all columns in the table and running db:push, then rename after and run db:push again.
Want results from more Discord servers?
Add your server