All checks were successful
Deploy production / deploy (push) Successful in 1m19s
33 lines
1.4 KiB
SQL
33 lines
1.4 KiB
SQL
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 $$;
|