[BUG]: SQLite/Turso libsql: Drizzle (Studio) not running functions when adding records
What version of drizzle-orm are you using?
0.30.9
What version of drizzle-kit are you using?
0.20.17
Describe the Bug
For a following table:
export const users = sqliteTable(
"organizations",
{
id: text("id")
.primaryKey()
.default(sql`(uuid4())`),
email: text("email").notNull(),
updatedAt: text("updated_at")
.notNull()
.default(sql`current_timestamp`),
);
CREATE TABLE `users` (
`id` text PRIMARY KEY DEFAULT (uuid4()) NOT NULL,
`email` text NOT NULL,
`updated_at` text DEFAULT current_timestamp NOT NULL
);
When I add a new record via Drizzle Studio, I noticed that the SQLite functions are not being fired. They work fine when adding records manually using SQL queries but not when I use Drizzle Runner or via "Add record" button. Interestingly, the behaviour is slightly different in both cases. I presume the same error will occur when executing the queries from code.
Expected behavior
Execute uuid4() and current_timestamp on row creation regardless of the method
Environment & setup
No response
This is happening to me as well. Doing e.g. createdAt: text("created_at").notNull().default(sql(current_timestamp)) will simply write (current_timestamp) to the database when editing in the studio. I presume this would also be the case when doing it programatically. What works, is using $default/$defaultFn instead like so: createdAt: text("created_at").notNull().$default(() => new Date().toISOString()), although this would only work at runtime, and not at the database level.
@Pramuspl @miguelrk Hey! This should be fixed, try it.