style: 统一代码风格 — 格式化 auth schema、修复 setup 页面 return 语句、规范 drizzle snapshot

This commit is contained in:
2026-03-31 22:46:47 +08:00
parent 9f39e7f7e8
commit dcccf6675f
4 changed files with 151 additions and 172 deletions
+12 -36
View File
@@ -110,12 +110,8 @@
"name": "account_user_id_user_id_fk", "name": "account_user_id_user_id_fk",
"tableFrom": "account", "tableFrom": "account",
"tableTo": "user", "tableTo": "user",
"columnsFrom": [ "columnsFrom": ["user_id"],
"user_id" "columnsTo": ["id"],
],
"columnsTo": [
"id"
],
"onDelete": "cascade", "onDelete": "cascade",
"onUpdate": "no action" "onUpdate": "no action"
} }
@@ -202,12 +198,8 @@
"name": "session_user_id_user_id_fk", "name": "session_user_id_user_id_fk",
"tableFrom": "session", "tableFrom": "session",
"tableTo": "user", "tableTo": "user",
"columnsFrom": [ "columnsFrom": ["user_id"],
"user_id" "columnsTo": ["id"],
],
"columnsTo": [
"id"
],
"onDelete": "cascade", "onDelete": "cascade",
"onUpdate": "no action" "onUpdate": "no action"
} }
@@ -217,9 +209,7 @@
"session_token_unique": { "session_token_unique": {
"name": "session_token_unique", "name": "session_token_unique",
"nullsNotDistinct": false, "nullsNotDistinct": false,
"columns": [ "columns": ["token"]
"token"
]
} }
}, },
"policies": {}, "policies": {},
@@ -283,9 +273,7 @@
"user_email_unique": { "user_email_unique": {
"name": "user_email_unique", "name": "user_email_unique",
"nullsNotDistinct": false, "nullsNotDistinct": false,
"columns": [ "columns": ["email"]
"email"
]
} }
}, },
"policies": {}, "policies": {},
@@ -434,12 +422,8 @@
"name": "bookmark_category_id_category_id_fk", "name": "bookmark_category_id_category_id_fk",
"tableFrom": "bookmark", "tableFrom": "bookmark",
"tableTo": "category", "tableTo": "category",
"columnsFrom": [ "columnsFrom": ["category_id"],
"category_id" "columnsTo": ["id"],
],
"columnsTo": [
"id"
],
"onDelete": "cascade", "onDelete": "cascade",
"onUpdate": "no action" "onUpdate": "no action"
}, },
@@ -447,12 +431,8 @@
"name": "bookmark_user_id_user_id_fk", "name": "bookmark_user_id_user_id_fk",
"tableFrom": "bookmark", "tableFrom": "bookmark",
"tableTo": "user", "tableTo": "user",
"columnsFrom": [ "columnsFrom": ["user_id"],
"user_id" "columnsTo": ["id"],
],
"columnsTo": [
"id"
],
"onDelete": "cascade", "onDelete": "cascade",
"onUpdate": "no action" "onUpdate": "no action"
} }
@@ -527,12 +507,8 @@
"name": "category_user_id_user_id_fk", "name": "category_user_id_user_id_fk",
"tableFrom": "category", "tableFrom": "category",
"tableTo": "user", "tableTo": "user",
"columnsFrom": [ "columnsFrom": ["user_id"],
"user_id" "columnsTo": ["id"],
],
"columnsTo": [
"id"
],
"onDelete": "cascade", "onDelete": "cascade",
"onUpdate": "no action" "onUpdate": "no action"
} }
+4 -1
View File
@@ -52,7 +52,9 @@ function SetupPage() {
router.navigate({ to: '/' as never }) router.navigate({ to: '/' as never })
} }
;<div className="min-h-screen bg-slate-50 flex items-center justify-center px-4">
return (
<div className="min-h-screen bg-slate-50 flex items-center justify-center px-4">
<div className="w-full max-w-md"> <div className="w-full max-w-md">
<div className="text-center mb-8"> <div className="text-center mb-8">
<h1 className="text-4xl font-bold text-slate-900 tracking-tight">Kairos</h1> <h1 className="text-4xl font-bold text-slate-900 tracking-tight">Kairos</h1>
@@ -138,4 +140,5 @@ function SetupPage() {
</div> </div>
</div> </div>
</div> </div>
)
} }
+52 -52
View File
@@ -1,93 +1,93 @@
import { relations } from "drizzle-orm"; import { relations } from 'drizzle-orm'
import { pgTable, text, timestamp, boolean, index } from "drizzle-orm/pg-core"; import { boolean, index, pgTable, text, timestamp } from 'drizzle-orm/pg-core'
export const user = pgTable("user", { export const user = pgTable('user', {
id: text("id").primaryKey(), id: text('id').primaryKey(),
name: text("name").notNull(), name: text('name').notNull(),
email: text("email").notNull().unique(), email: text('email').notNull().unique(),
emailVerified: boolean("email_verified").default(false).notNull(), emailVerified: boolean('email_verified').default(false).notNull(),
image: text("image"), image: text('image'),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp("updated_at") updatedAt: timestamp('updated_at')
.defaultNow() .defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); })
export const session = pgTable( export const session = pgTable(
"session", 'session',
{ {
id: text("id").primaryKey(), id: text('id').primaryKey(),
expiresAt: timestamp("expires_at").notNull(), expiresAt: timestamp('expires_at').notNull(),
token: text("token").notNull().unique(), token: text('token').notNull().unique(),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp("updated_at") updatedAt: timestamp('updated_at')
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
ipAddress: text("ip_address"), ipAddress: text('ip_address'),
userAgent: text("user_agent"), userAgent: text('user_agent'),
userId: text("user_id") userId: text('user_id')
.notNull() .notNull()
.references(() => user.id, { onDelete: "cascade" }), .references(() => user.id, { onDelete: 'cascade' }),
}, },
(table) => [index("session_userId_idx").on(table.userId)], (table) => [index('session_userId_idx').on(table.userId)],
); )
export const account = pgTable( export const account = pgTable(
"account", 'account',
{ {
id: text("id").primaryKey(), id: text('id').primaryKey(),
accountId: text("account_id").notNull(), accountId: text('account_id').notNull(),
providerId: text("provider_id").notNull(), providerId: text('provider_id').notNull(),
userId: text("user_id") userId: text('user_id')
.notNull() .notNull()
.references(() => user.id, { onDelete: "cascade" }), .references(() => user.id, { onDelete: 'cascade' }),
accessToken: text("access_token"), accessToken: text('access_token'),
refreshToken: text("refresh_token"), refreshToken: text('refresh_token'),
idToken: text("id_token"), idToken: text('id_token'),
accessTokenExpiresAt: timestamp("access_token_expires_at"), accessTokenExpiresAt: timestamp('access_token_expires_at'),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), refreshTokenExpiresAt: timestamp('refresh_token_expires_at'),
scope: text("scope"), scope: text('scope'),
password: text("password"), password: text('password'),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp("updated_at") updatedAt: timestamp('updated_at')
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}, },
(table) => [index("account_userId_idx").on(table.userId)], (table) => [index('account_userId_idx').on(table.userId)],
); )
export const verification = pgTable( export const verification = pgTable(
"verification", 'verification',
{ {
id: text("id").primaryKey(), id: text('id').primaryKey(),
identifier: text("identifier").notNull(), identifier: text('identifier').notNull(),
value: text("value").notNull(), value: text('value').notNull(),
expiresAt: timestamp("expires_at").notNull(), expiresAt: timestamp('expires_at').notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp("updated_at") updatedAt: timestamp('updated_at')
.defaultNow() .defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}, },
(table) => [index("verification_identifier_idx").on(table.identifier)], (table) => [index('verification_identifier_idx').on(table.identifier)],
); )
export const userRelations = relations(user, ({ many }) => ({ export const userRelations = relations(user, ({ many }) => ({
sessions: many(session), sessions: many(session),
accounts: many(account), accounts: many(account),
})); }))
export const sessionRelations = relations(session, ({ one }) => ({ export const sessionRelations = relations(session, ({ one }) => ({
user: one(user, { user: one(user, {
fields: [session.userId], fields: [session.userId],
references: [user.id], references: [user.id],
}), }),
})); }))
export const accountRelations = relations(account, ({ one }) => ({ export const accountRelations = relations(account, ({ one }) => ({
user: one(user, { user: one(user, {
fields: [account.userId], fields: [account.userId],
references: [user.id], references: [user.id],
}), }),
})); }))