drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: PlanetScale error when using `(now() + interval 14 day)` as default

Open maoosi opened this issue 1 year ago • 2 comments

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

maoosi avatar May 23 '23 05:05 maoosi

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?

steviec avatar May 25 '23 22:05 steviec

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.

maoosi avatar May 26 '23 00:05 maoosi

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.

Angelelz avatar Dec 18 '23 20:12 Angelelz