You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
import { sql } from "drizzle-orm";
|
|
|
|
export const users = sqliteTable("users", {
|
|
id: integer().primaryKey(),
|
|
username: text().notNull().unique(),
|
|
email: text(),
|
|
nickname: text(),
|
|
password: text().notNull(),
|
|
avatar: text(),
|
|
role: text().notNull().default("user"),
|
|
status: text().notNull().default("active"),
|
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
|
|
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
.defaultNow()
|
|
.$onUpdate(() => new Date())
|
|
.notNull(),
|
|
});
|
|
|
|
export const sessions = sqliteTable(
|
|
"sessions",
|
|
{
|
|
id: text().primaryKey(),
|
|
userId: integer("user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
|
|
},
|
|
(table) => [index("sessions_user_id_idx").on(table.userId)],
|
|
);
|
|
|
|
export const oauthAccounts = sqliteTable("oauth_accounts", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: integer("user_id").notNull(),
|
|
provider: text("provider").notNull(),
|
|
providerUserId: text("provider_user_id").notNull(),
|
|
username: text("username"),
|
|
email: text("email"),
|
|
avatar: text("avatar"),
|
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).default(
|
|
sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`,
|
|
),
|
|
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).default(
|
|
sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`,
|
|
),
|
|
});
|
|
|