drizzle-orm
drizzle-orm copied to clipboard
[BUG]: PlanetScale error when using `(now() + interval 14 day)` as default
What version of drizzle-orm
are you using?
0.26.0
What version of drizzle-kit
are you using?
0.18.0
Describe the Bug
Using MySQL + PlanetScale and (now() + interval 14 day)
as the default returns an unexpected error.
export const User = mysqlTable('User', {
trialExpiresAt: datetime('trialExpiresAt', { fsp: 3 }).notNull().default(sql`(now() + interval 14 day)`),
}
Running drizzle-kit push:mysql
on the above schema will return the following PlanetScale error (shortened):
Error: Invalid default value for 'trialExpiresAt'.
Expected behavior
The expected behaviour is the same as running the below code:
await db.execute(
sql.raw(`ALTER TABLE User CHANGE \`trialExpiresAt\` \`trialExpiresAt\` datetime(3) NOT NULL DEFAULT (now() + interval 14 day);`)
);
In that case, everything is working as expected and there are no errors returned from PlanetScale.
Environment & setup
No response
This is probably a duplicate of https://github.com/drizzle-team/drizzle-orm/issues/472. If you change it to now(3) + interval 14 day
does it fix your problem?
If you change it to now(3) + interval 14 day does it fix your problem?
Still the same issue, however removing the fsp
option and using (now() + interval 14 day)
works.
I don't think this is a drizzle issue. If you define a custom default you should verify if it's supported in planetscale. You might need to try:
...
trialExpiresAt: datetime('trialExpiresAt', { fsp: 3 }).notNull().default(sql`(current_timestamp(3) + interval 14 day)`)
...
I'll close this issue but please feel free to re-open if you have more issues.