groceries: stats page with nightly snapshot (battles, basket, promos, CPI, range)
All checks were successful
Deploy production / deploy (push) Successful in 1m19s

This commit is contained in:
2026-10-25 20:38:55 +00:00
parent c4397e9d59
commit a6ef263c7e
11 changed files with 35731 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
CREATE TABLE "groceries"."item_sizes" (
"id" serial PRIMARY KEY,
"item_id" integer NOT NULL,
"observed_on" date NOT NULL,
"unit" text,
"unit_amount" numeric(12,4),
"size_text" text,
"price_cents" integer,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "groceries"."stats_snapshots" (
"id" serial PRIMARY KEY,
"computed_on" date NOT NULL,
"scope" text NOT NULL,
"computed_at" timestamp with time zone DEFAULT now() NOT NULL,
"duration_ms" integer,
"data" jsonb NOT NULL,
"series" jsonb,
CONSTRAINT "stats_snapshots_scope_check" CHECK ("scope" IN ('food','all'))
);
--> statement-breakpoint
CREATE UNIQUE INDEX "item_sizes_item_day_key" ON "groceries"."item_sizes" ("item_id","observed_on");--> statement-breakpoint
CREATE UNIQUE INDEX "stats_snapshots_day_scope_key" ON "groceries"."stats_snapshots" ("computed_on","scope");--> statement-breakpoint
ALTER TABLE "groceries"."item_sizes" ADD CONSTRAINT "item_sizes_item_id_items_id_fkey" FOREIGN KEY ("item_id") REFERENCES "groceries"."items"("id") ON DELETE CASCADE;--> statement-breakpoint
DO $$
BEGIN
IF current_user = 'personal' AND EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_app') THEN
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA groceries TO personal_app;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA groceries TO personal_app;
END IF;
END $$;

File diff suppressed because it is too large Load Diff