add9365250
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.
59 lines
3.5 KiB
SQL
59 lines
3.5 KiB
SQL
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"); |