91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import { pgTable, text, timestamp, boolean, integer } from "drizzle-orm/pg-core";
|
|
|
|
// Roles enum
|
|
export const roleEnum = ["user", "admin", "moderator"] as const;
|
|
export type UserRole = typeof roleEnum[number];
|
|
|
|
// Better-auth requires these tables
|
|
export const user = pgTable("user", {
|
|
id: text("id").primaryKey(),
|
|
name: text("name").notNull(),
|
|
email: text("email").notNull().unique(),
|
|
emailVerified: boolean("emailVerified").notNull().default(false),
|
|
image: text("image"),
|
|
role: text("role").notNull().default("user"), // user, admin, moderator
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
});
|
|
|
|
export const session = pgTable("session", {
|
|
id: text("id").primaryKey(),
|
|
expiresAt: timestamp("expiresAt").notNull(),
|
|
token: text("token").notNull().unique(),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
ipAddress: text("ipAddress"),
|
|
userAgent: text("userAgent"),
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: "cascade" }),
|
|
});
|
|
|
|
export const account = pgTable("account", {
|
|
id: text("id").primaryKey(),
|
|
accountId: text("accountId").notNull(),
|
|
providerId: text("providerId").notNull(),
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: "cascade" }),
|
|
accessToken: text("accessToken"),
|
|
refreshToken: text("refreshToken"),
|
|
idToken: text("idToken"),
|
|
accessTokenExpiresAt: timestamp("accessTokenExpiresAt"),
|
|
refreshTokenExpiresAt: timestamp("refreshTokenExpiresAt"),
|
|
scope: text("scope"),
|
|
password: text("password"),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
});
|
|
|
|
export const verification = pgTable("verification", {
|
|
id: text("id").primaryKey(),
|
|
identifier: text("identifier").notNull(),
|
|
value: text("value").notNull(),
|
|
expiresAt: timestamp("expiresAt").notNull(),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
});
|
|
|
|
export const images = pgTable("images", {
|
|
id: text("id").primaryKey(),
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: "cascade" }),
|
|
originalName: text("originalName").notNull(),
|
|
fileName: text("fileName").notNull(),
|
|
filePath: text("filePath").notNull(),
|
|
url: text("url").notNull(),
|
|
width: integer("width"),
|
|
height: integer("height"),
|
|
quality: integer("quality"),
|
|
format: text("format").notNull(),
|
|
fileSize: integer("fileSize").notNull(),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
});
|
|
|
|
// API Keys for external applications
|
|
export const apiKeys = pgTable("apiKeys", {
|
|
id: text("id").primaryKey(),
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: "cascade" }),
|
|
name: text("name").notNull(), // API key ismi (örn: "Mobile App", "Dashboard")
|
|
key: text("key").notNull().unique(), // API key
|
|
lastUsedAt: timestamp("lastUsedAt"),
|
|
expiresAt: timestamp("expiresAt"), // null = süresiz
|
|
isActive: boolean("isActive").notNull().default(true),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
});
|