hellth-hub/packages/db/drizzle/0015_recipe_submissions.sql
Sebastian Mayer 2436dd9cac Initial commit: Hellth Hub monorepo
Mobile-first Web-App fuer persoenliches Health-, Ernaehrungs-,
Aktivitaets- und Einkaufs-Tracking im Home-Lab-Betrieb.

Stack: pnpm Monorepo - Next.js 16 + React 19 + Tailwind (apps/admin) -
Hono + tRPC + Better Auth mit 2FA und Passkeys (packages/api) -
PostgreSQL + Drizzle ORM (packages/db) - Docker fuer Postgres und pgAdmin.

Module:
- Auth mit Login, 2FA (TOTP + Backup-Codes), Passkeys und Admin-Recovery
- Tagesansicht mit Essen, Trinken, Gewicht, Aktivitaeten und Coach-Hinweisen
- Lebensmittelkatalog mit Naehrwerten, Portionen, OCR/Barcode/Open Food Facts
- Rezepte mit Live-Naehrwertberechnung und Community-Vorschlaegen
- Essensplanung und Wochenbudget mit Sportbonus
- Einkaufslisten mit Maerkten und Laufweg-Sortierung
- Hellfireclub mit Aktivitaetspunkten und gemeinsamer Aktivitaetsplanung
- Wearables-Vorbereitung (Fitbit / Google Fit / Health Connect)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 22:15:16 +02:00

37 lines
2.6 KiB
SQL

CREATE TABLE "recipe_submissions" (
"id" text PRIMARY KEY NOT NULL,
"userId" text NOT NULL,
"name" text NOT NULL,
"portions" integer DEFAULT 1 NOT NULL,
"minutes" integer DEFAULT 0 NOT NULL,
"notes" text,
"mealPrepDays" integer DEFAULT 0 NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"reviewNote" text,
"reviewedBy" text,
"reviewedAt" timestamp,
"acceptedRecipeId" text,
"createdAt" timestamp DEFAULT now() NOT NULL,
"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "recipe_submission_ingredients" (
"id" text PRIMARY KEY NOT NULL,
"submissionId" text NOT NULL,
"foodId" text NOT NULL,
"amountG" numeric(8, 2) NOT NULL,
"displayAmount" numeric(8, 2),
"displayUnit" "portion_unit",
"portionId" text,
"sortOrder" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
ALTER TABLE "recipe_submissions" ADD CONSTRAINT "recipe_submissions_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_submissions" ADD CONSTRAINT "recipe_submissions_reviewedBy_user_id_fk" FOREIGN KEY ("reviewedBy") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_submissions" ADD CONSTRAINT "recipe_submissions_acceptedRecipeId_recipes_id_fk" FOREIGN KEY ("acceptedRecipeId") REFERENCES "public"."recipes"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_submission_ingredients" ADD CONSTRAINT "recipe_submission_ingredients_submissionId_recipe_submissions_id_fk" FOREIGN KEY ("submissionId") REFERENCES "public"."recipe_submissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_submission_ingredients" ADD CONSTRAINT "recipe_submission_ingredients_foodId_foods_id_fk" FOREIGN KEY ("foodId") REFERENCES "public"."foods"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_submission_ingredients" ADD CONSTRAINT "recipe_submission_ingredients_portionId_food_portions_id_fk" FOREIGN KEY ("portionId") REFERENCES "public"."food_portions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "recipe_submissions_user_idx" ON "recipe_submissions" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "recipe_submissions_status_idx" ON "recipe_submissions" USING btree ("status","createdAt");--> statement-breakpoint
CREATE INDEX "recipe_submission_ingredients_submission_idx" ON "recipe_submission_ingredients" USING btree ("submissionId");--> statement-breakpoint