drizzle-orm
drizzle-orm copied to clipboard
[BUG]: planetscale - now() and current_timestamp() doesn't work when FSP is specified for timestamp
What version of drizzle-orm are you using?
0.23.13
What version of drizzle-kit are you using?
0.17.4
Describe the Bug
Create table fails on planetscale if FSP not specified for now() and current_timestamp
CREATE TABLE `test_table` (
`created_at` timestamp(2) NOT NULL DEFAULT (now())
);
leads to
ERROR 1067 (42000): target: ***.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'created_at' (errno 1067) (sqlstate 42000) (CallerID: planetscale-admin): Sql: "create table test_table (\n\tcreated_at timestamp(2) not null default now()\n)", BindVars: {REDACTED}
but it works if the FSP is added
CREATE TABLE `test_table` (
`created_at` timestamp(2) NOT NULL DEFAULT (now(2))
);
the same is valid for current_timestamp
CREATE TABLE `test_table2` (
`updated_at` timestamp(2) NOT NULL DEFAULT (now(2)) ON UPDATE CURRENT_TIMESTAMP
);
ERROR 1294 (HY000): target: ***.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid ON UPDATE clause for 'updated_at' column (errno 1294) (sqlstate HY000) (CallerID: planetscale-admin): Sql: "create table test_table2 (\n\tupdated_at timestamp(2) not null default now(2) on update current_timestamp()\n)", BindVars: {REDACTED}
it works for
CREATE TABLE `test_table2` (
`updated_at` timestamp(2) NOT NULL DEFAULT (now(2)) ON UPDATE CURRENT_TIMESTAMP(2)
);
Expected behavior
No response
Environment & setup
No response
Thanks! Will add this fix. Currently for defaults you can use
.default(sql`(now(2))`)
.default(sql`CURRENT_TIMESTAMP(2)`)
For onUpdate no workarounds for now. Only by manually changing sql file before applying it to database
I have this same issue. I can manually change the sql, but it's blocking me from using my planetscale push:mysql workflow :(.