Setting default timestamp in user table

So Im using turso with sqlite and out of nowhere i have been issuing this issue with my user table, im using nextauthjs
import { sql } from 'drizzle-orm';
import { sqliteTable, text, primaryKey, integer, int } from 'drizzle-orm/sqlite-core';
import type { AdapterAccountType } from 'next-auth/adapters';
import { createId } from '@paralleldrive/cuid2';

export const user = sqliteTable('user', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
name: text('name'),
email: text('email').notNull(),
emailVerified: integer('emailVerified', { mode: 'timestamp_ms' }),
image: text('image'),
role: text('role').$type<'USER' | 'ADMIN'>().notNull().default('USER'),
joinedAt: integer('joinedAt', { mode: 'timestamp_ms' })
.notNull()
.$defaultFn(() => sql`(unixepoch() * 1000)`),
});
import { sql } from 'drizzle-orm';
import { sqliteTable, text, primaryKey, integer, int } from 'drizzle-orm/sqlite-core';
import type { AdapterAccountType } from 'next-auth/adapters';
import { createId } from '@paralleldrive/cuid2';

export const user = sqliteTable('user', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
name: text('name'),
email: text('email').notNull(),
emailVerified: integer('emailVerified', { mode: 'timestamp_ms' }),
image: text('image'),
role: text('role').$type<'USER' | 'ADMIN'>().notNull().default('USER'),
joinedAt: integer('joinedAt', { mode: 'timestamp_ms' })
.notNull()
.$defaultFn(() => sql`(unixepoch() * 1000)`),
});
1 Reply
Mykhailo
Mykhailo6mo ago
Hey @Aryxst! What issue did you face? By the way, you can check this guide to set timestamp as a default value https://orm.drizzle.team/learn/guides/timestamp-default-value#sqlite
Drizzle ORM - SQL Timestamp as a default value
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server