weirdness with sql`CURRENT

Here's my simple schema
export const sageTransactions = sqliteTable('sageTransactions', {
id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),
createdAt: text('created_at')
.default(sql<string>`CURRENT_TIMESTAMP`)
.notNull(),
transactionId: text('transaction_id').notNull(),
user: integer('user').notNull(),
date: text('date').notNull(),
ledger: text('ledger').notNull(),
content: text('content').notNull(),
})
export const sageTransactions = sqliteTable('sageTransactions', {
id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),
createdAt: text('created_at')
.default(sql<string>`CURRENT_TIMESTAMP`)
.notNull(),
transactionId: text('transaction_id').notNull(),
user: integer('user').notNull(),
date: text('date').notNull(),
ledger: text('ledger').notNull(),
content: text('content').notNull(),
})
However when I look at what's in studio all I see is the rows all defaulting to the text be actually "sqlCURRENT_TIMESTAMP" in the created_at field? What did I miss? Sorry complete newbie here.
No description
4 Replies
Mykhailo
Mykhailo7mo ago
Hey @andystevenson! It's a bug, will be fixed. Btw, you should do like this:
.default(sql<string>`(CURRENT_TIMESTAMP)`),
.default(sql<string>`(CURRENT_TIMESTAMP)`),
This is to ensure that CURRENT_TIMESTAMP is a constraint and not a string
andystevenson
andystevensonOP7mo ago
Hi @Mykhailo , thanks for responding so quick. I think I actually tried that... same result... let me try again!
Mykhailo
Mykhailo7mo ago
It won't fix your issue because there is a problem in drizzle studio. But team knows this bug, so it will be fixed:) (CURRENT_TIMESTAMP) instead of CURRENT_TIMESTAMP just prevents issues that could be raised by push command because Drizzle Kit can misidentify if it is a string or constraint, so parentheses are important
andystevenson
andystevensonOP7mo ago
Thanks
Want results from more Discord servers?
Add your server