feat(db): Drizzle ORM schema and migrations

Schema domains: users/auth, recipes, social, meal-planning, tiers/usage, webhooks.
Includes Better Auth tables, audit_logs, site_settings, push_subscriptions,
user_model_prefs, user_nutrition_goals. Migrations 0000–0008 applied.
This commit is contained in:
Arnaud
2026-07-01 08:08:44 +02:00
parent ae7c5d943e
commit add9365250
39 changed files with 25552 additions and 0 deletions
@@ -0,0 +1,338 @@
CREATE TYPE "public"."tier" AS ENUM('free', 'pro');--> statement-breakpoint
CREATE TYPE "public"."unit_pref" AS ENUM('metric', 'imperial');--> statement-breakpoint
CREATE TYPE "public"."user_role" AS ENUM('user', 'moderator', 'admin');--> statement-breakpoint
CREATE TYPE "public"."difficulty" AS ENUM('easy', 'medium', 'hard');--> statement-breakpoint
CREATE TYPE "public"."visibility" AS ENUM('private', 'unlisted', 'public');--> statement-breakpoint
CREATE TYPE "public"."feed_item_type" AS ENUM('new_recipe', 'new_follow', 'recipe_rated');--> statement-breakpoint
CREATE TYPE "public"."meal_type" AS ENUM('breakfast', 'lunch', 'dinner', 'snack');--> statement-breakpoint
CREATE TYPE "public"."weekday" AS ENUM('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');--> statement-breakpoint
CREATE TABLE "accounts" (
"id" text PRIMARY KEY NOT NULL,
"account_id" text NOT NULL,
"provider_id" text NOT NULL,
"user_id" text NOT NULL,
"access_token" text,
"refresh_token" text,
"id_token" text,
"access_token_expires_at" timestamp,
"refresh_token_expires_at" timestamp,
"scope" text,
"password" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "api_keys" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"name" text NOT NULL,
"key_hash" text NOT NULL,
"last_used_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "api_keys_key_hash_unique" UNIQUE("key_hash")
);
--> statement-breakpoint
CREATE TABLE "sessions" (
"id" text PRIMARY KEY NOT NULL,
"expires_at" timestamp NOT NULL,
"token" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"ip_address" text,
"user_agent" text,
"user_id" text NOT NULL,
CONSTRAINT "sessions_token_unique" UNIQUE("token")
);
--> statement-breakpoint
CREATE TABLE "user_follows" (
"follower_id" text NOT NULL,
"following_id" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" text PRIMARY KEY NOT NULL,
"email" text NOT NULL,
"email_verified" boolean DEFAULT false NOT NULL,
"name" text NOT NULL,
"avatar_url" text,
"bio" text,
"username" text,
"role" "user_role" DEFAULT 'user' NOT NULL,
"tier" "tier" DEFAULT 'free' NOT NULL,
"unit_pref" "unit_pref" DEFAULT 'metric' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "users_email_unique" UNIQUE("email"),
CONSTRAINT "users_username_unique" UNIQUE("username")
);
--> statement-breakpoint
CREATE TABLE "verifications" (
"id" text PRIMARY KEY NOT NULL,
"identifier" text NOT NULL,
"value" text NOT NULL,
"expires_at" timestamp NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ingredients" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"aliases" text[] DEFAULT '{}' NOT NULL,
"category" text,
"known_allergens" text[] DEFAULT '{}' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "ingredients_name_unique" UNIQUE("name")
);
--> statement-breakpoint
CREATE TABLE "recipe_ingredients" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"ingredient_id" text,
"raw_name" text NOT NULL,
"quantity" numeric(10, 4),
"unit" text,
"note" text,
"order" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE "recipe_notes" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"user_id" text NOT NULL,
"content" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "recipe_photos" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"storage_key" text NOT NULL,
"order" integer DEFAULT 0 NOT NULL,
"is_cover" boolean DEFAULT false NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "recipe_steps" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"order" integer NOT NULL,
"instruction" text NOT NULL,
"timer_seconds" integer,
"photo_url" text
);
--> statement-breakpoint
CREATE TABLE "recipe_variations" (
"id" text PRIMARY KEY NOT NULL,
"parent_recipe_id" text NOT NULL,
"child_recipe_id" text NOT NULL,
"description" text,
"ai_generated" boolean DEFAULT false NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "recipes" (
"id" text PRIMARY KEY NOT NULL,
"author_id" text NOT NULL,
"title" text NOT NULL,
"description" text,
"base_servings" integer DEFAULT 4 NOT NULL,
"visibility" "visibility" DEFAULT 'private' NOT NULL,
"source_url" text,
"ai_generated" boolean DEFAULT false NOT NULL,
"ai_model" text,
"ai_prompt" text,
"dietary_tags" jsonb DEFAULT '{}'::jsonb,
"dietary_verified" boolean DEFAULT false NOT NULL,
"difficulty" "difficulty",
"prep_mins" integer,
"cook_mins" integer,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user_allergens" (
"user_id" text NOT NULL,
"allergen_tag" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "collection_recipes" (
"collection_id" text NOT NULL,
"recipe_id" text NOT NULL,
"added_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "collections" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"name" text NOT NULL,
"description" text,
"is_public" boolean DEFAULT false NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "comments" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"user_id" text NOT NULL,
"parent_id" text,
"content" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cooking_history" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"recipe_id" text NOT NULL,
"cooked_at" timestamp DEFAULT now() NOT NULL,
"servings" integer,
"notes" text
);
--> statement-breakpoint
CREATE TABLE "favorites" (
"user_id" text NOT NULL,
"recipe_id" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "feed_items" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"type" "feed_item_type" NOT NULL,
"actor_id" text NOT NULL,
"subject_id" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ratings" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"user_id" text NOT NULL,
"score" integer NOT NULL,
"review_text" text,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "meal_plan_entries" (
"id" text PRIMARY KEY NOT NULL,
"meal_plan_id" text NOT NULL,
"day" "weekday" NOT NULL,
"meal_type" "meal_type" NOT NULL,
"recipe_id" text,
"servings" integer DEFAULT 2 NOT NULL,
"note" text
);
--> statement-breakpoint
CREATE TABLE "meal_plans" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"week_start" date NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "pantry_items" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"ingredient_id" text,
"raw_name" text NOT NULL,
"quantity" numeric(10, 4),
"unit" text,
"expires_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "shopping_list_items" (
"id" text PRIMARY KEY NOT NULL,
"list_id" text NOT NULL,
"ingredient_id" text,
"raw_name" text NOT NULL,
"quantity" numeric(10, 4),
"unit" text,
"aisle" text,
"checked" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE "shopping_lists" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text,
"name" text NOT NULL,
"generated_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "audit_logs" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text,
"action" text NOT NULL,
"target_type" text,
"target_id" text,
"metadata" text,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "tier_definitions" (
"tier" "tier" PRIMARY KEY NOT NULL,
"max_recipes" integer NOT NULL,
"ai_calls_per_month" integer NOT NULL,
"storage_mb" integer NOT NULL,
"max_public_recipes" integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user_usage" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"month" text NOT NULL,
"ai_calls_used" integer DEFAULT 0 NOT NULL,
"recipe_count" integer DEFAULT 0 NOT NULL,
"storage_used_mb" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_follows" ADD CONSTRAINT "user_follows_follower_id_users_id_fk" FOREIGN KEY ("follower_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_follows" ADD CONSTRAINT "user_follows_following_id_users_id_fk" FOREIGN KEY ("following_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_ingredients" ADD CONSTRAINT "recipe_ingredients_ingredient_id_ingredients_id_fk" FOREIGN KEY ("ingredient_id") REFERENCES "public"."ingredients"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_notes" ADD CONSTRAINT "recipe_notes_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_notes" ADD CONSTRAINT "recipe_notes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_photos" ADD CONSTRAINT "recipe_photos_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_steps" ADD CONSTRAINT "recipe_steps_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_variations" ADD CONSTRAINT "recipe_variations_parent_recipe_id_recipes_id_fk" FOREIGN KEY ("parent_recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_variations" ADD CONSTRAINT "recipe_variations_child_recipe_id_recipes_id_fk" FOREIGN KEY ("child_recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipes" ADD CONSTRAINT "recipes_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_allergens" ADD CONSTRAINT "user_allergens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "collection_recipes" ADD CONSTRAINT "collection_recipes_collection_id_collections_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "collection_recipes" ADD CONSTRAINT "collection_recipes_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "collections" ADD CONSTRAINT "collections_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "comments" ADD CONSTRAINT "comments_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "cooking_history" ADD CONSTRAINT "cooking_history_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "cooking_history" ADD CONSTRAINT "cooking_history_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "favorites" ADD CONSTRAINT "favorites_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "favorites" ADD CONSTRAINT "favorites_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "feed_items" ADD CONSTRAINT "feed_items_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "feed_items" ADD CONSTRAINT "feed_items_actor_id_users_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ratings" ADD CONSTRAINT "ratings_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ratings" ADD CONSTRAINT "ratings_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "meal_plan_entries" ADD CONSTRAINT "meal_plan_entries_meal_plan_id_meal_plans_id_fk" FOREIGN KEY ("meal_plan_id") REFERENCES "public"."meal_plans"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "meal_plan_entries" ADD CONSTRAINT "meal_plan_entries_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "meal_plans" ADD CONSTRAINT "meal_plans_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "pantry_items" ADD CONSTRAINT "pantry_items_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "pantry_items" ADD CONSTRAINT "pantry_items_ingredient_id_ingredients_id_fk" FOREIGN KEY ("ingredient_id") REFERENCES "public"."ingredients"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "shopping_list_items" ADD CONSTRAINT "shopping_list_items_list_id_shopping_lists_id_fk" FOREIGN KEY ("list_id") REFERENCES "public"."shopping_lists"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "shopping_list_items" ADD CONSTRAINT "shopping_list_items_ingredient_id_ingredients_id_fk" FOREIGN KEY ("ingredient_id") REFERENCES "public"."ingredients"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "shopping_lists" ADD CONSTRAINT "shopping_lists_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_usage" ADD CONSTRAINT "user_usage_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "recipes_author_idx" ON "recipes" USING btree ("author_id");--> statement-breakpoint
CREATE INDEX "recipes_visibility_idx" ON "recipes" USING btree ("visibility");--> statement-breakpoint
CREATE INDEX "comments_recipe_idx" ON "comments" USING btree ("recipe_id");--> statement-breakpoint
CREATE INDEX "feed_items_user_idx" ON "feed_items" USING btree ("user_id","created_at");--> statement-breakpoint
CREATE INDEX "audit_logs_created_idx" ON "audit_logs" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "user_usage_user_month_idx" ON "user_usage" USING btree ("user_id","month");
@@ -0,0 +1 @@
ALTER TABLE "user_usage" ADD CONSTRAINT "user_usage_user_month_uniq" UNIQUE("user_id","month");
@@ -0,0 +1 @@
ALTER TABLE "recipes" ADD COLUMN "nutrition_data" jsonb;
@@ -0,0 +1,23 @@
CREATE TABLE "webhook_deliveries" (
"id" text PRIMARY KEY NOT NULL,
"webhook_id" text NOT NULL,
"event" text NOT NULL,
"payload" jsonb,
"status_code" integer,
"success" boolean DEFAULT false NOT NULL,
"attempts" integer DEFAULT 0 NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "webhooks" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"url" text NOT NULL,
"events" text[] DEFAULT '{}' NOT NULL,
"secret" text NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_webhook_id_webhooks_id_fk" FOREIGN KEY ("webhook_id") REFERENCES "public"."webhooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "webhooks" ADD CONSTRAINT "webhooks_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1 @@
ALTER TABLE "users" ADD COLUMN "locale" text DEFAULT 'en' NOT NULL;
@@ -0,0 +1,9 @@
CREATE TABLE "user_ai_keys" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"provider" text NOT NULL,
"encrypted_key" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "user_ai_keys" ADD CONSTRAINT "user_ai_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,59 @@
CREATE TYPE "public"."collection_member_role" AS ENUM('viewer', 'editor');--> statement-breakpoint
CREATE TYPE "public"."comment_reaction_type" AS ENUM('like', 'love', 'laugh', 'wow', 'sad', 'fire');--> statement-breakpoint
CREATE TABLE "push_subscriptions" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"endpoint" text NOT NULL,
"p256dh" text NOT NULL,
"auth" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "push_subscriptions_endpoint_unique" UNIQUE("endpoint")
);
--> statement-breakpoint
CREATE TABLE "user_nutrition_goals" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"calories_kcal" integer,
"protein_g" integer,
"carbs_g" integer,
"fat_g" integer,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "user_nutrition_goals_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
CREATE TABLE "recipe_snapshots" (
"id" text PRIMARY KEY NOT NULL,
"recipe_id" text NOT NULL,
"author_id" text NOT NULL,
"version" integer NOT NULL,
"title" text NOT NULL,
"snapshot_data" jsonb NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "collection_members" (
"id" text PRIMARY KEY NOT NULL,
"collection_id" text NOT NULL,
"user_id" text NOT NULL,
"role" "collection_member_role" DEFAULT 'viewer' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "comment_reactions" (
"id" text PRIMARY KEY NOT NULL,
"comment_id" text NOT NULL,
"user_id" text NOT NULL,
"type" "comment_reaction_type" NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "push_subscriptions" ADD CONSTRAINT "push_subscriptions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_nutrition_goals" ADD CONSTRAINT "user_nutrition_goals_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_snapshots" ADD CONSTRAINT "recipe_snapshots_recipe_id_recipes_id_fk" FOREIGN KEY ("recipe_id") REFERENCES "public"."recipes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "recipe_snapshots" ADD CONSTRAINT "recipe_snapshots_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "collection_members" ADD CONSTRAINT "collection_members_collection_id_collections_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "collection_members" ADD CONSTRAINT "collection_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "comment_reactions" ADD CONSTRAINT "comment_reactions_comment_id_comments_id_fk" FOREIGN KEY ("comment_id") REFERENCES "public"."comments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "comment_reactions" ADD CONSTRAINT "comment_reactions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "recipe_snapshots_recipe_idx" ON "recipe_snapshots" USING btree ("recipe_id","version");--> statement-breakpoint
CREATE INDEX "comment_reactions_comment_idx" ON "comment_reactions" USING btree ("comment_id");
@@ -0,0 +1,14 @@
CREATE TABLE "user_model_prefs" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"text_provider" text,
"text_model" text,
"vision_provider" text,
"vision_model" text,
"meal_plan_provider" text,
"meal_plan_model" text,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "user_model_prefs_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
ALTER TABLE "user_model_prefs" ADD CONSTRAINT "user_model_prefs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,9 @@
CREATE TABLE "site_settings" (
"key" text PRIMARY KEY NOT NULL,
"value" text,
"is_secret" boolean DEFAULT false NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"updated_by_id" text
);
--> statement-breakpoint
ALTER TABLE "site_settings" ADD CONSTRAINT "site_settings_updated_by_id_users_id_fk" FOREIGN KEY ("updated_by_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,69 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1782374484140,
"tag": "0000_motionless_cardiac",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1782394660764,
"tag": "0001_curvy_crystal",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1782408717265,
"tag": "0002_freezing_prowler",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1782408796095,
"tag": "0003_robust_bullseye",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1782854086888,
"tag": "0004_chemical_deadpool",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1782854378834,
"tag": "0005_massive_spot",
"breakpoints": true
},
{
"idx": 6,
"version": "7",
"when": 1782856370142,
"tag": "0006_worthless_roxanne_simpson",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1782859664569,
"tag": "0007_majestic_retro_girl",
"breakpoints": true
},
{
"idx": 8,
"version": "7",
"when": 1782883184215,
"tag": "0008_violet_centennial",
"breakpoints": true
}
]
}