|
1 | | -import { integer, pgTable, varchar } from "drizzle-orm/pg-core"; |
| 1 | +import { |
| 2 | + integer, |
| 3 | + pgTable, |
| 4 | + varchar, |
| 5 | + text, |
| 6 | + timestamp, |
| 7 | + boolean, |
| 8 | +} from "drizzle-orm/pg-core"; |
2 | 9 |
|
3 | 10 | export const usersTable = pgTable("users", { |
4 | | - id: integer().primaryKey().generatedAlwaysAsIdentity(), |
5 | | - name: varchar({ length: 255 }).notNull(), |
6 | | - age: integer().notNull(), |
7 | | - email: varchar({ length: 255 }).notNull().unique(), |
| 11 | + id: integer().primaryKey().generatedAlwaysAsIdentity(), |
| 12 | + name: varchar({ length: 255 }).notNull(), |
| 13 | + age: integer().notNull(), |
| 14 | + email: varchar({ length: 255 }).notNull().unique(), |
| 15 | +}); |
| 16 | + |
| 17 | +// better-auth |
| 18 | +export const user = pgTable("user", { |
| 19 | + id: text("id").primaryKey(), |
| 20 | + name: text("name").notNull(), |
| 21 | + email: text("email").notNull().unique(), |
| 22 | + emailVerified: boolean("email_verified").default(false).notNull(), |
| 23 | + image: text("image"), |
| 24 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 25 | + updatedAt: timestamp("updated_at") |
| 26 | + .defaultNow() |
| 27 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 28 | + .notNull(), |
| 29 | +}); |
| 30 | + |
| 31 | +export const session = pgTable("session", { |
| 32 | + id: text("id").primaryKey(), |
| 33 | + expiresAt: timestamp("expires_at").notNull(), |
| 34 | + token: text("token").notNull().unique(), |
| 35 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 36 | + updatedAt: timestamp("updated_at") |
| 37 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 38 | + .notNull(), |
| 39 | + ipAddress: text("ip_address"), |
| 40 | + userAgent: text("user_agent"), |
| 41 | + userId: text("user_id") |
| 42 | + .notNull() |
| 43 | + .references(() => user.id, { onDelete: "cascade" }), |
| 44 | +}); |
| 45 | + |
| 46 | +export const account = pgTable("account", { |
| 47 | + id: text("id").primaryKey(), |
| 48 | + accountId: text("account_id").notNull(), |
| 49 | + providerId: text("provider_id").notNull(), |
| 50 | + userId: text("user_id") |
| 51 | + .notNull() |
| 52 | + .references(() => user.id, { onDelete: "cascade" }), |
| 53 | + accessToken: text("access_token"), |
| 54 | + refreshToken: text("refresh_token"), |
| 55 | + idToken: text("id_token"), |
| 56 | + accessTokenExpiresAt: timestamp("access_token_expires_at"), |
| 57 | + refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), |
| 58 | + scope: text("scope"), |
| 59 | + password: text("password"), |
| 60 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 61 | + updatedAt: timestamp("updated_at") |
| 62 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 63 | + .notNull(), |
| 64 | +}); |
| 65 | + |
| 66 | +export const verification = pgTable("verification", { |
| 67 | + id: text("id").primaryKey(), |
| 68 | + identifier: text("identifier").notNull(), |
| 69 | + value: text("value").notNull(), |
| 70 | + expiresAt: timestamp("expires_at").notNull(), |
| 71 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 72 | + updatedAt: timestamp("updated_at") |
| 73 | + .defaultNow() |
| 74 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 75 | + .notNull(), |
8 | 76 | }); |
0 commit comments