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.
27 lines
890 B
27 lines
890 B
import { sql } from "drizzle-orm";
|
|
import { index, integer, pgTable, timestamp, varchar } from "drizzle-orm/pg-core";
|
|
|
|
export const users = pgTable("users", {
|
|
id: integer().primaryKey(),
|
|
username: varchar().notNull().unique(),
|
|
email: varchar(),
|
|
nickname: varchar(),
|
|
password: varchar().notNull(),
|
|
avatar: varchar(),
|
|
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
updatedAt: timestamp('updated_at')
|
|
.defaultNow()
|
|
.$onUpdate(() => sql`CURRENT_TIMESTAMP`)
|
|
.notNull(),
|
|
});
|
|
|
|
export const sessions = pgTable("sessions", {
|
|
id: varchar().primaryKey(),
|
|
userId: integer("user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
}, (table) => [
|
|
index("sessions_user_id_idx").on(table.userId),
|
|
]);
|