Cannot read properties of undefined (reading 'endsWith')
Y try to push this in my supabase database
export const user_provider_topics = pgTable( 'influencer_topics', { uuid: uuid().defaultRandom().primaryKey().notNull(), topic: text().notNull(), created_at: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(), updated_at: timestamp('updated_at', { mode: 'string' }).defaultNow().notNull(), }, (table) => { return { userProviderTopicUuidUnique: unique('user_provider_topic_uuid_unique').on( table.uuid ), } } )but i recivied this errorNo config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/lauti/Documents/pich-monorepo/drizzle.config.ts' Using 'postgres' driver for database querying [⡿] Pulling schema from database... /Users/lauti/Documents/pich-monorepo/node_modules/drizzle-kit/bin.cjs:20568 if (column7.column_default.endsWith("[]")) { ^ TypeError: Cannot read properties of undefined (reading 'endsWith') at defaultForColumn (/Users/lauti/Documents/pich-monorepo/node_modules/drizzle-kit/bin.cjs:20568:34) at /Users/lauti/Documents/pich-monorepo/node_modules/drizzle-kit/bin.cjs:20168:36 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)>
18 Replies
@Andrii Sherman
any idea?
@rphlmr ⚡
im using this version "drizzle-orm": "^0.36.0",
and this for the kit "drizzle-kit": "^0.27.1",
Hello 👋 I can find where it happens in drizzle-kit.
@Andrew Sherman it's on
defaultForColumn
in pgSerializer
.
We are testing for column.column_default === null
but it doesn't catch undefined
(should be column.column_default == null
)Working on a fix for it
column_default should never be an undefined
there is no such type in database
@lauti to reproduce it, I would need to know
- did you have anything in your database before pushing? I suppose yes. Please send me all the tables you had in a database(just structure)
it will help me to find why default in your case was undefined
I suppose it's only Supabase related
sure
export const userTable = pgTable(
'user',
{
uuid: uuid('uuid').defaultRandom().primaryKey().notNull(),
email: text('email').notNull(),
fullName: text('full_name').notNull(),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'string' }).defaultNow().notNull(),
paid: boolean('paid').default(false).notNull(),
avatarUrl: text('avatar_url'),
requestLimit: integer('request_limit').default(5).notNull(),
},
(table) => {
return {
userEmailUnique: unique('user_email_unique').on(table.email),
}
}
)
export const influencerProviderTopics = pgTable(
'influencer_provider_topics',
{
uuid: uuid('uuid').defaultRandom().primaryKey().notNull(),
topic: text('topic').notNull(),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'string' }).defaultNow().notNull(),
},
(table) => ({
influencerProviderTopicsUuidUnique: unique('influencer_provider_topics_uuid_unique').on(
table.uuid
),
})
)
export const providerInfluencers = pgTable(
'provider_influencers',
{
uuid: uuid('uuid').defaultRandom().primaryKey().notNull(),
workPlatformId: uuid('work_platform_id').notNull(),
workPlatformName: text('work_platform_name').notNull(),
workPlatformLogoUrl: text('work_platform_logo_url').notNull(),
platformUsername: text('platform_username').notNull(),
externalId: text('external_id').notNull(),
url: text('url').notNull(),
imageUrl: text('image_url'),
fullName: text('full_name'),
introduction: text('introduction'),
isVerified: boolean('is_verified').default(false).notNull(),
platformAccountType: text('platform_account_type'),
gender: text('gender'),
ageGroup: text('age_group'),
language: text('language'),
followerCount: integer('follower_count'),
subscriberCount: integer('subscriber_count'),
contentCount: integer('content_count'),
engagementRate: numeric('engagement_rate'),
averageLikes: integer('average_likes'),
averageViews: integer('average_views'),
creatorLocationCity: text('creator_location_city'),
creatorLocationState: text('creator_location_state'),
creatorLocationCountry: text('creator_location_country'),
contactDetailType: text('contact_detail_type'),
topicUuid: uuid('topic_uuid').references(() => influencerProviderTopics.uuid, {
onDelete: 'set null',
}),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'string' }).defaultNow().notNull(),
},
(table) => {
return {
providerInfluencersUuidUnique: unique('provider_influencers_uuid_unique').on(table.uuid),
}
}
)
export const influencer_topic = pgTable(
'influencer_topic',
{
uuid: uuid('uuid').defaultRandom().primaryKey().notNull(),
influencerUuid: uuid('influencer_uuid')
.references(() => providerInfluencers.uuid, { onDelete: 'cascade' })
.notNull(),
topicUuid: uuid('topic_uuid')
.references(() => influencerProviderTopics.uuid, { onDelete: 'cascade' })
.notNull(),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'string' }).defaultNow().notNull(),
},
(table) => ({
influencerTopicUuidUnique: unique('influencer_topic_uuid_unique').on(table.uuid),
})
)
the error comes when i tried to push or pull influencerProviderTopics
then I downloaded these versions “drizzle-kit”: “^0.24.0”, “drizzle-orm”: “^0.33.0” and the error didn't appear
but I got this new error
error TypeError: Cannot read properties of undefined (reading 'toLowerCase')
@Andrew Sherman @Raphaël M (@rphlmr) ⚡
I hope this information will help you
ok I know why now
@lauti does your connection string uses the port
6543
? (Supabase Transaction mode)yes
can you try with
5432
(session mode)
You can have an 'env' you use only in your Drizzle config (I have MIGRATION_DATABASE_URL
with the connection string using port 5432
).sure, but the mode of the db cause this error? why?
TypeError: Cannot read properties of undefined (reading 'endsWith')
Because 6543 is a special mode for serverless (client open and close a connection on each transactions) and 5432 is a "stable" connection
6543 is a Supabase thing with Supavisor (their pooler)
I would even advise using a direct connection for migrations/push, etc.
postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-ID].supabase.co:5432/postgres
ohh okey
make sense...
i'll try with this port
I'm pushing a few fixes for policies we had
and then will double-check if I can reproduce your issue
perfect
thanks
can u show me how the config would be? because if i add session mode all my app is in session mode..
@Raphaël M (@rphlmr) ⚡
I have not found the solution in the documents
in your supabase dashboard, you can select the mode to display
Then you copy this string. It should be the same as your previous string, only the port changes.
I would suggest adding another environment to your project just for drizzle.config. For your app, use what is best depending on your server.
Yes I understood that, but how should be the connection to supabase in the drizzle configuration? In my local I use session mode and in production I use transaction mode?
@Raphaël M (@rphlmr) ⚡
What's in your drizzle.config is only for drizzle-kit (push, pull, migrate, introspect). This one needs to be on 5432.
___
For your app, your
drizzle()
client, it depends on your production platform.
For example, port 6543
doesn't allow prepared
queries and requires pg
or postgres
drivers to disable this feature. But this is the go to for serverless target (vercel, azure function, etc).
If you deploy on Fly.io or Digital Ocean long running server, you can choose 5432.
(https://supabase.com/docs/guides/database/connecting-to-postgres#connecting-to-external-libraries-and-tools)