Some checks are pending
CI / Lint, Typecheck, Test, Build (push) Waiting to run
CI-Pipeline (Forgejo Actions): - .forgejo/workflows/ci.yml: lint + typecheck + test + admin build - typecheck-Scripts in packages/api, packages/db, apps/admin ergaenzt - ESLint FlatConfig (eslint-config-next 16) in apps/admin angelegt - React-19-Hook-Findings im bestehenden Code als Warnings markiert (set-state-in-effect, preserve-manual-memoization, no-unused-vars) DB-Schema-Split: - packages/db/src/schema/health.ts (636 Zeilen, Monolith) entfernt und auf 7 Domain-Module aufgeteilt: profiles, foods, stores, recipes, tracking, shopping, community. index.ts re-exportiert alles. API-Refactoring: - 2FA-Middleware: 2 DB-Queries pro Admin-Call sind jetzt lazy + per-Request gecached. Bei tRPC-Batch-Requests mit mehreren protected Procedures wird der 2FA-State nur einmal geladen (siehe context.ts getTwoFactorState). - any-Typen in trpc/init.ts und trpc/routers/health.ts entfernt; Drizzle inferiert Closure-Typen automatisch. - packages/api/src/trpc/routers/health/_shared.ts: alle Helper-Funktionen und Zod-Input-Schemas aus health.ts extrahiert. health.ts: 2419 -> 2061 Zeilen. Vorbereitung fuer Procedure-Split in Folge-Session. Konfiguration: - .env.example um alle in turbo.json deklarierten Env-Vars erweitert, jeweils mit Kontext-Kommentar. - turbo.json um real genutzte Env-Vars erweitert: NEXT_PUBLIC_HELP_URL, ENABLE_DB_MIGRATIONS, ADMIN_INITIAL_PASSWORD, DEMO_RECIPE_OWNER_EMAIL. - .gitignore: *.tsbuildinfo (TypeScript-Build-Cache). - apps/admin/lib/hellth-data.test.ts: fehlendes Recipe.minutes Feld in Mocks. Offene Folge-Sessions: - Vollstaendiger Procedure-Split von routers/health.ts in Sub-Files - Aufteilung von apps/admin/lib/hellth-data.ts (1149 Zeilen) in Domain-Module Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
109 lines
4.2 KiB
TypeScript
109 lines
4.2 KiB
TypeScript
import {
|
|
boolean,
|
|
index,
|
|
integer,
|
|
numeric,
|
|
pgTable,
|
|
text,
|
|
timestamp,
|
|
uniqueIndex,
|
|
} from "drizzle-orm/pg-core";
|
|
import { user } from "./auth";
|
|
import { foods, foodPortions } from "./foods";
|
|
import { portionUnitEnum } from "./enums";
|
|
|
|
export const recipes = pgTable(
|
|
"recipes",
|
|
{
|
|
id: text("id").primaryKey(),
|
|
ownerUserId: text("ownerUserId").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
name: text("name").notNull(),
|
|
portions: integer("portions").notNull().default(1),
|
|
minutes: integer("minutes").notNull().default(0),
|
|
notes: text("notes"),
|
|
mealPrepDays: integer("mealPrepDays").notNull().default(0),
|
|
isPublic: boolean("isPublic").notNull().default(false),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
},
|
|
(table) => ({
|
|
ownerIdx: index("recipes_owner_idx").on(table.ownerUserId),
|
|
}),
|
|
);
|
|
|
|
export const recipeIngredients = pgTable(
|
|
"recipe_ingredients",
|
|
{
|
|
id: text("id").primaryKey(),
|
|
recipeId: text("recipeId").notNull().references(() => recipes.id, { onDelete: "cascade" }),
|
|
foodId: text("foodId").notNull().references(() => foods.id, { onDelete: "restrict" }),
|
|
amountG: numeric("amountG", { precision: 8, scale: 2 }).notNull(),
|
|
displayAmount: numeric("displayAmount", { precision: 8, scale: 2 }),
|
|
displayUnit: portionUnitEnum("displayUnit"),
|
|
portionId: text("portionId").references(() => foodPortions.id, { onDelete: "set null" }),
|
|
sortOrder: integer("sortOrder").notNull().default(0),
|
|
},
|
|
(table) => ({
|
|
recipeIdx: index("recipe_ingredients_recipe_idx").on(table.recipeId),
|
|
}),
|
|
);
|
|
|
|
export const recipeSubmissions = pgTable(
|
|
"recipe_submissions",
|
|
{
|
|
id: text("id").primaryKey(),
|
|
userId: text("userId").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
name: text("name").notNull(),
|
|
portions: integer("portions").notNull().default(1),
|
|
minutes: integer("minutes").notNull().default(0),
|
|
notes: text("notes"),
|
|
mealPrepDays: integer("mealPrepDays").notNull().default(0),
|
|
status: text("status").notNull().default("pending"),
|
|
reviewNote: text("reviewNote"),
|
|
reviewedBy: text("reviewedBy").references(() => user.id, { onDelete: "set null" }),
|
|
reviewedAt: timestamp("reviewedAt"),
|
|
acceptedRecipeId: text("acceptedRecipeId").references(() => recipes.id, { onDelete: "set null" }),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
},
|
|
(table) => ({
|
|
userIdx: index("recipe_submissions_user_idx").on(table.userId),
|
|
statusIdx: index("recipe_submissions_status_idx").on(table.status, table.createdAt),
|
|
}),
|
|
);
|
|
|
|
export const recipeSubmissionIngredients = pgTable(
|
|
"recipe_submission_ingredients",
|
|
{
|
|
id: text("id").primaryKey(),
|
|
submissionId: text("submissionId").notNull().references(() => recipeSubmissions.id, { onDelete: "cascade" }),
|
|
foodId: text("foodId").notNull().references(() => foods.id, { onDelete: "restrict" }),
|
|
amountG: numeric("amountG", { precision: 8, scale: 2 }).notNull(),
|
|
displayAmount: numeric("displayAmount", { precision: 8, scale: 2 }),
|
|
displayUnit: portionUnitEnum("displayUnit"),
|
|
portionId: text("portionId").references(() => foodPortions.id, { onDelete: "set null" }),
|
|
sortOrder: integer("sortOrder").notNull().default(0),
|
|
},
|
|
(table) => ({
|
|
submissionIdx: index("recipe_submission_ingredients_submission_idx").on(table.submissionId),
|
|
}),
|
|
);
|
|
|
|
export const recipeRatings = pgTable(
|
|
"recipe_ratings",
|
|
{
|
|
id: text("id").primaryKey(),
|
|
recipeId: text("recipeId").notNull().references(() => recipes.id, { onDelete: "cascade" }),
|
|
userId: text("userId").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
rating: integer("rating").notNull(),
|
|
comment: text("comment"),
|
|
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
|
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
|
|
},
|
|
(table) => ({
|
|
uniqueUserRecipe: uniqueIndex("recipe_ratings_user_recipe_unique").on(table.recipeId, table.userId),
|
|
}),
|
|
);
|
|
|
|
export type Recipe = typeof recipes.$inferSelect;
|
|
export type NewRecipe = typeof recipes.$inferInsert;
|