mirror of
https://github.com/jakejarvis/stanza.git
synced 2026-10-16 06:15:43 -04:00
- split better-auth drizzle adapters into separate postgres/sqlite variants with a dedicated sqlite schema template - simplify auth-client templates to use `createAuthClient()` without an explicit baseURL - export `Node` type and `SyntaxKind` enum from the codemods package - add codemod for the auth-clerk module
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
|
|
|
// SQLite has no native boolean or timestamp types. We use:
|
|
// - integer(...) with mode "boolean" for booleans (0/1)
|
|
// - integer(...) with mode "timestamp" for timestamps (epoch seconds)
|
|
// Defaults are applied in JS via .$defaultFn() since SQLite's CURRENT_TIMESTAMP
|
|
// would store as ISO text, which doesn't round-trip cleanly with the mode.
|
|
|
|
export const user = sqliteTable("user", {
|
|
id: text("id").primaryKey(),
|
|
name: text("name").notNull(),
|
|
email: text("email").notNull().unique(),
|
|
emailVerified: integer("email_verified", { mode: "boolean" }).notNull().default(false),
|
|
image: text("image"),
|
|
createdAt: integer("created_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
updatedAt: integer("updated_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
});
|
|
|
|
export const session = sqliteTable("session", {
|
|
id: text("id").primaryKey(),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: "cascade" }),
|
|
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
|
|
token: text("token").notNull(),
|
|
ipAddress: text("ip_address"),
|
|
userAgent: text("user_agent"),
|
|
createdAt: integer("created_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
updatedAt: integer("updated_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
});
|
|
|
|
export const account = sqliteTable("account", {
|
|
id: text("id").primaryKey(),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: "cascade" }),
|
|
accountId: text("account_id").notNull(),
|
|
providerId: text("provider_id").notNull(),
|
|
accessToken: text("access_token"),
|
|
refreshToken: text("refresh_token"),
|
|
idToken: text("id_token"),
|
|
accessTokenExpiresAt: integer("access_token_expires_at", { mode: "timestamp" }),
|
|
refreshTokenExpiresAt: integer("refresh_token_expires_at", { mode: "timestamp" }),
|
|
scope: text("scope"),
|
|
password: text("password"),
|
|
createdAt: integer("created_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
updatedAt: integer("updated_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
});
|
|
|
|
export const verification = sqliteTable("verification", {
|
|
id: text("id").primaryKey(),
|
|
identifier: text("identifier").notNull(),
|
|
value: text("value").notNull(),
|
|
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
|
|
createdAt: integer("created_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
updatedAt: integer("updated_at", { mode: "timestamp" })
|
|
.notNull()
|
|
.$defaultFn(() => new Date()),
|
|
});
|