399 lines
22 KiB
MySQL
399 lines
22 KiB
MySQL
|
|
CREATE TYPE "public"."activity_level" AS ENUM('low', 'moderate', 'active');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."activity_source" AS ENUM('manual', 'fitbit', 'health_connect', 'system');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."coach_priority" AS ENUM('high', 'medium', 'low');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."diet_style" AS ENUM('mixed', 'vegetarian', 'vegan', 'low_carb', 'flexible');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."food_source" AS ENUM('seed', 'manual', 'openfoodfacts', 'ocr', 'community');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."health_goal" AS ENUM('lose_weight', 'maintain', 'build_muscle', 'healthier');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."meal_type" AS ENUM('breakfast', 'lunch', 'dinner', 'snack');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."portion_unit" AS ENUM('g', 'ml', 'tsp', 'tbsp', 'piece', 'pack', 'bottle', 'cup', 'slice');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."reminder_kind" AS ENUM('water', 'snack', 'movement', 'meal', 'shopping', 'activity');--> statement-breakpoint
|
||
|
|
CREATE TYPE "public"."wearable_provider" AS ENUM('fitbit', 'health_connect', 'google_fit');--> statement-breakpoint
|
||
|
|
CREATE TABLE "activity_logs" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"templateId" text,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"minutes" integer DEFAULT 0 NOT NULL,
|
||
|
|
"points" integer DEFAULT 0 NOT NULL,
|
||
|
|
"calories" integer DEFAULT 0 NOT NULL,
|
||
|
|
"source" "activity_source" DEFAULT 'manual' NOT NULL,
|
||
|
|
"externalId" text,
|
||
|
|
"note" text,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "activity_templates" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"ownerUserId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"category" text DEFAULT 'habit' NOT NULL,
|
||
|
|
"defaultMinutes" integer DEFAULT 10 NOT NULL,
|
||
|
|
"defaultPoints" integer DEFAULT 10 NOT NULL,
|
||
|
|
"defaultCalories" integer DEFAULT 0 NOT NULL,
|
||
|
|
"icon" text DEFAULT 'custom' NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "club_activities" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"hostUserId" text NOT NULL,
|
||
|
|
"title" text NOT NULL,
|
||
|
|
"category" text DEFAULT 'other' NOT NULL,
|
||
|
|
"startsAt" timestamp NOT NULL,
|
||
|
|
"durationMinutes" integer DEFAULT 30 NOT NULL,
|
||
|
|
"points" integer DEFAULT 20 NOT NULL,
|
||
|
|
"note" text,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "club_activity_participants" (
|
||
|
|
"activityId" text NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"displayName" text NOT NULL,
|
||
|
|
"joinedAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"completedAt" timestamp,
|
||
|
|
CONSTRAINT "club_activity_participants_activityId_userId_pk" PRIMARY KEY("activityId","userId")
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "coach_principles" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"title" text NOT NULL,
|
||
|
|
"body" text NOT NULL,
|
||
|
|
"category" text DEFAULT 'general' NOT NULL,
|
||
|
|
"isActive" boolean DEFAULT true NOT NULL,
|
||
|
|
"sortOrder" integer DEFAULT 0 NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "coach_recommendations" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"title" text NOT NULL,
|
||
|
|
"body" text NOT NULL,
|
||
|
|
"priority" "coach_priority" DEFAULT 'medium' NOT NULL,
|
||
|
|
"category" text DEFAULT 'daily' NOT NULL,
|
||
|
|
"source" text DEFAULT 'rule' NOT NULL,
|
||
|
|
"validFrom" date,
|
||
|
|
"validTo" date,
|
||
|
|
"dismissedAt" timestamp,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "drink_logs" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"amountMl" integer NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "food_portions" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"foodId" text NOT NULL,
|
||
|
|
"label" text NOT NULL,
|
||
|
|
"unit" "portion_unit" NOT NULL,
|
||
|
|
"amount" numeric(8, 2) NOT NULL,
|
||
|
|
"gramsEquivalent" numeric(8, 2) NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "food_stores" (
|
||
|
|
"foodId" text NOT NULL,
|
||
|
|
"storeId" text NOT NULL,
|
||
|
|
"departmentId" text,
|
||
|
|
"lastPrice" numeric(8, 2),
|
||
|
|
"availabilityTags" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
CONSTRAINT "food_stores_foodId_storeId_pk" PRIMARY KEY("foodId","storeId")
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "foods" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"ownerUserId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"brand" text,
|
||
|
|
"barcode" text,
|
||
|
|
"category" text DEFAULT 'Sonstiges' NOT NULL,
|
||
|
|
"kcalPer100g" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"proteinPer100g" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"carbsPer100g" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"fatPer100g" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"servingG" numeric(8, 2) DEFAULT '100' NOT NULL,
|
||
|
|
"preferredUnit" "portion_unit" DEFAULT 'g' NOT NULL,
|
||
|
|
"densityGPerMl" numeric(8, 4),
|
||
|
|
"source" "food_source" DEFAULT 'manual' NOT NULL,
|
||
|
|
"isVerified" boolean DEFAULT false NOT NULL,
|
||
|
|
"isCommunity" boolean DEFAULT false NOT NULL,
|
||
|
|
"availableEverywhere" boolean DEFAULT true NOT NULL,
|
||
|
|
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "health_goals" (
|
||
|
|
"userId" text PRIMARY KEY NOT NULL,
|
||
|
|
"drinkMl" integer DEFAULT 2500 NOT NULL,
|
||
|
|
"calories" integer DEFAULT 2000 NOT NULL,
|
||
|
|
"carbsG" integer DEFAULT 200 NOT NULL,
|
||
|
|
"fatG" integer DEFAULT 67 NOT NULL,
|
||
|
|
"proteinG" integer DEFAULT 150 NOT NULL,
|
||
|
|
"weightKg" numeric(6, 2),
|
||
|
|
"fastingHours" integer DEFAULT 12 NOT NULL,
|
||
|
|
"weeklyCalories" integer,
|
||
|
|
"sportAddsCalories" boolean DEFAULT true NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "health_profiles" (
|
||
|
|
"userId" text PRIMARY KEY NOT NULL,
|
||
|
|
"goal" "health_goal" DEFAULT 'healthier' NOT NULL,
|
||
|
|
"age" integer,
|
||
|
|
"heightCm" numeric(6, 2),
|
||
|
|
"currentWeightKg" numeric(6, 2),
|
||
|
|
"targetWeightKg" numeric(6, 2),
|
||
|
|
"activityLevel" "activity_level" DEFAULT 'moderate' NOT NULL,
|
||
|
|
"dietStyle" "diet_style" DEFAULT 'flexible' NOT NULL,
|
||
|
|
"mealsPerDay" integer DEFAULT 3 NOT NULL,
|
||
|
|
"cookingTime" text DEFAULT 'medium' NOT NULL,
|
||
|
|
"budgetFocus" boolean DEFAULT false NOT NULL,
|
||
|
|
"excludedFoods" text,
|
||
|
|
"biggestChallenge" text,
|
||
|
|
"medicalNote" boolean DEFAULT false NOT NULL,
|
||
|
|
"completedAt" timestamp,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "meal_logs" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"mealType" "meal_type" NOT NULL,
|
||
|
|
"foodId" text,
|
||
|
|
"recipeId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"amountLabel" text,
|
||
|
|
"amountG" numeric(8, 2),
|
||
|
|
"calories" integer DEFAULT 0 NOT NULL,
|
||
|
|
"proteinG" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"carbsG" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"fatG" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"source" text DEFAULT 'manual' NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "meal_plans" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"mealType" "meal_type" NOT NULL,
|
||
|
|
"recipeId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"portions" numeric(8, 2) DEFAULT '1' NOT NULL,
|
||
|
|
"note" text,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "recipe_ingredients" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"recipeId" 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
|
||
|
|
CREATE TABLE "recipe_ratings" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"recipeId" text NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"rating" integer NOT NULL,
|
||
|
|
"comment" text,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "recipes" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"ownerUserId" 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,
|
||
|
|
"isPublic" boolean DEFAULT false NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "reminder_rules" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"kind" "reminder_kind" NOT NULL,
|
||
|
|
"enabled" boolean DEFAULT true NOT NULL,
|
||
|
|
"intervalMinutes" integer DEFAULT 90 NOT NULL,
|
||
|
|
"startTime" text DEFAULT '08:00' NOT NULL,
|
||
|
|
"endTime" text DEFAULT '20:00' NOT NULL,
|
||
|
|
"message" text NOT NULL,
|
||
|
|
"quietDays" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "shopping_list_items" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"shoppingListId" text NOT NULL,
|
||
|
|
"foodId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"category" text DEFAULT 'Sonstiges' NOT NULL,
|
||
|
|
"amountG" numeric(8, 2) DEFAULT '0' NOT NULL,
|
||
|
|
"purchaseAmount" text,
|
||
|
|
"checked" boolean DEFAULT false NOT NULL,
|
||
|
|
"sortOrder" integer DEFAULT 0 NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "shopping_lists" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"storeId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"startsOn" date,
|
||
|
|
"endsOn" date,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "store_departments" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"storeId" text NOT NULL,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"sortOrder" integer DEFAULT 0 NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "stores" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"ownerUserId" text,
|
||
|
|
"name" text NOT NULL,
|
||
|
|
"favorite" boolean DEFAULT false NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "wearable_connections" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"provider" "wearable_provider" NOT NULL,
|
||
|
|
"providerUserId" text,
|
||
|
|
"accessTokenEncrypted" text,
|
||
|
|
"refreshTokenEncrypted" text,
|
||
|
|
"scopes" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||
|
|
"expiresAt" timestamp,
|
||
|
|
"lastSyncAt" timestamp,
|
||
|
|
"syncEnabled" boolean DEFAULT true NOT NULL,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "wearable_imports" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"connectionId" text NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"provider" "wearable_provider" NOT NULL,
|
||
|
|
"externalId" text NOT NULL,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||
|
|
"importedAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "weekly_calorie_plans" (
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"plannedCalories" integer NOT NULL,
|
||
|
|
"note" text,
|
||
|
|
"updatedAt" timestamp DEFAULT now() NOT NULL,
|
||
|
|
CONSTRAINT "weekly_calorie_plans_userId_date_pk" PRIMARY KEY("userId","date")
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
CREATE TABLE "weight_logs" (
|
||
|
|
"id" text PRIMARY KEY NOT NULL,
|
||
|
|
"userId" text NOT NULL,
|
||
|
|
"date" date NOT NULL,
|
||
|
|
"weightKg" numeric(6, 2) NOT NULL,
|
||
|
|
"note" text,
|
||
|
|
"createdAt" timestamp DEFAULT now() NOT NULL
|
||
|
|
);
|
||
|
|
--> statement-breakpoint
|
||
|
|
ALTER TABLE "activity_logs" ADD CONSTRAINT "activity_logs_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "activity_logs" ADD CONSTRAINT "activity_logs_templateId_activity_templates_id_fk" FOREIGN KEY ("templateId") REFERENCES "public"."activity_templates"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "activity_templates" ADD CONSTRAINT "activity_templates_ownerUserId_user_id_fk" FOREIGN KEY ("ownerUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "club_activities" ADD CONSTRAINT "club_activities_hostUserId_user_id_fk" FOREIGN KEY ("hostUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "club_activity_participants" ADD CONSTRAINT "club_activity_participants_activityId_club_activities_id_fk" FOREIGN KEY ("activityId") REFERENCES "public"."club_activities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "club_activity_participants" ADD CONSTRAINT "club_activity_participants_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "coach_recommendations" ADD CONSTRAINT "coach_recommendations_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "drink_logs" ADD CONSTRAINT "drink_logs_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "food_portions" ADD CONSTRAINT "food_portions_foodId_foods_id_fk" FOREIGN KEY ("foodId") REFERENCES "public"."foods"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "food_stores" ADD CONSTRAINT "food_stores_foodId_foods_id_fk" FOREIGN KEY ("foodId") REFERENCES "public"."foods"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "food_stores" ADD CONSTRAINT "food_stores_storeId_stores_id_fk" FOREIGN KEY ("storeId") REFERENCES "public"."stores"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "food_stores" ADD CONSTRAINT "food_stores_departmentId_store_departments_id_fk" FOREIGN KEY ("departmentId") REFERENCES "public"."store_departments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "foods" ADD CONSTRAINT "foods_ownerUserId_user_id_fk" FOREIGN KEY ("ownerUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "health_goals" ADD CONSTRAINT "health_goals_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "health_profiles" ADD CONSTRAINT "health_profiles_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "meal_logs" ADD CONSTRAINT "meal_logs_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "meal_logs" ADD CONSTRAINT "meal_logs_foodId_foods_id_fk" FOREIGN KEY ("foodId") REFERENCES "public"."foods"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "meal_logs" ADD CONSTRAINT "meal_logs_recipeId_recipes_id_fk" FOREIGN KEY ("recipeId") REFERENCES "public"."recipes"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "meal_plans" ADD CONSTRAINT "meal_plans_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "meal_plans" ADD CONSTRAINT "meal_plans_recipeId_recipes_id_fk" FOREIGN KEY ("recipeId") REFERENCES "public"."recipes"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_recipeId_recipes_id_fk" FOREIGN KEY ("recipeId") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_foodId_foods_id_fk" FOREIGN KEY ("foodId") REFERENCES "public"."foods"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_portionId_food_portions_id_fk" FOREIGN KEY ("portionId") REFERENCES "public"."food_portions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "recipe_ratings" ADD CONSTRAINT "recipe_ratings_recipeId_recipes_id_fk" FOREIGN KEY ("recipeId") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "recipe_ratings" ADD CONSTRAINT "recipe_ratings_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "recipes" ADD CONSTRAINT "recipes_ownerUserId_user_id_fk" FOREIGN KEY ("ownerUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "reminder_rules" ADD CONSTRAINT "reminder_rules_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "shopping_list_items" ADD CONSTRAINT "shopping_list_items_shoppingListId_shopping_lists_id_fk" FOREIGN KEY ("shoppingListId") REFERENCES "public"."shopping_lists"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "shopping_list_items" ADD CONSTRAINT "shopping_list_items_foodId_foods_id_fk" FOREIGN KEY ("foodId") REFERENCES "public"."foods"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "shopping_lists" ADD CONSTRAINT "shopping_lists_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "shopping_lists" ADD CONSTRAINT "shopping_lists_storeId_stores_id_fk" FOREIGN KEY ("storeId") REFERENCES "public"."stores"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "store_departments" ADD CONSTRAINT "store_departments_storeId_stores_id_fk" FOREIGN KEY ("storeId") REFERENCES "public"."stores"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "stores" ADD CONSTRAINT "stores_ownerUserId_user_id_fk" FOREIGN KEY ("ownerUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "wearable_connections" ADD CONSTRAINT "wearable_connections_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "wearable_imports" ADD CONSTRAINT "wearable_imports_connectionId_wearable_connections_id_fk" FOREIGN KEY ("connectionId") REFERENCES "public"."wearable_connections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "wearable_imports" ADD CONSTRAINT "wearable_imports_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "weekly_calorie_plans" ADD CONSTRAINT "weekly_calorie_plans_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
ALTER TABLE "weight_logs" ADD CONSTRAINT "weight_logs_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||
|
|
CREATE INDEX "activity_logs_user_date_idx" ON "activity_logs" USING btree ("userId","date");--> statement-breakpoint
|
||
|
|
CREATE UNIQUE INDEX "activity_logs_source_external_unique" ON "activity_logs" USING btree ("userId","source","externalId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "activity_templates_owner_idx" ON "activity_templates" USING btree ("ownerUserId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "club_activities_starts_at_idx" ON "club_activities" USING btree ("startsAt");--> statement-breakpoint
|
||
|
|
CREATE INDEX "coach_recommendations_user_idx" ON "coach_recommendations" USING btree ("userId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "drink_logs_user_date_idx" ON "drink_logs" USING btree ("userId","date");--> statement-breakpoint
|
||
|
|
CREATE INDEX "food_portions_food_idx" ON "food_portions" USING btree ("foodId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "food_stores_store_idx" ON "food_stores" USING btree ("storeId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "foods_owner_idx" ON "foods" USING btree ("ownerUserId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "foods_barcode_idx" ON "foods" USING btree ("barcode");--> statement-breakpoint
|
||
|
|
CREATE INDEX "foods_name_idx" ON "foods" USING btree ("name");--> statement-breakpoint
|
||
|
|
CREATE INDEX "meal_logs_user_date_idx" ON "meal_logs" USING btree ("userId","date");--> statement-breakpoint
|
||
|
|
CREATE INDEX "meal_plans_user_date_idx" ON "meal_plans" USING btree ("userId","date");--> statement-breakpoint
|
||
|
|
CREATE INDEX "recipe_ingredients_recipe_idx" ON "recipe_ingredients" USING btree ("recipeId");--> statement-breakpoint
|
||
|
|
CREATE UNIQUE INDEX "recipe_ratings_user_recipe_unique" ON "recipe_ratings" USING btree ("recipeId","userId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "recipes_owner_idx" ON "recipes" USING btree ("ownerUserId");--> statement-breakpoint
|
||
|
|
CREATE UNIQUE INDEX "reminder_rules_user_kind_unique" ON "reminder_rules" USING btree ("userId","kind");--> statement-breakpoint
|
||
|
|
CREATE INDEX "shopping_list_items_list_idx" ON "shopping_list_items" USING btree ("shoppingListId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "shopping_lists_user_idx" ON "shopping_lists" USING btree ("userId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "store_departments_store_idx" ON "store_departments" USING btree ("storeId");--> statement-breakpoint
|
||
|
|
CREATE UNIQUE INDEX "wearable_connections_user_provider_unique" ON "wearable_connections" USING btree ("userId","provider");--> statement-breakpoint
|
||
|
|
CREATE UNIQUE INDEX "wearable_imports_provider_external_unique" ON "wearable_imports" USING btree ("provider","externalId");--> statement-breakpoint
|
||
|
|
CREATE INDEX "wearable_imports_user_date_idx" ON "wearable_imports" USING btree ("userId","date");--> statement-breakpoint
|
||
|
|
CREATE UNIQUE INDEX "weight_logs_user_date_unique" ON "weight_logs" USING btree ("userId","date");--> statement-breakpoint
|
||
|
|
ALTER TABLE "user" DROP COLUMN "lastName";--> statement-breakpoint
|
||
|
|
ALTER TABLE "user" DROP COLUMN "phone";--> statement-breakpoint
|
||
|
|
ALTER TABLE "user" DROP COLUMN "mobile";--> statement-breakpoint
|
||
|
|
ALTER TABLE "user" DROP COLUMN "street";--> statement-breakpoint
|
||
|
|
ALTER TABLE "user" DROP COLUMN "postalCode";--> statement-breakpoint
|
||
|
|
ALTER TABLE "user" DROP COLUMN "city";
|