61db8eb661
Re-implement lost commit from worktree cleanup. PR #12 already has UAT_PLAYBOOK + factories fix; add all missing core implementation: - Add petSizeCategoryEnum/coatTypeEnum to schema - Add bufferRules table with service FK + unique constraint - Add defaultBufferMinutes column to services table - Change pets.coatType/petSizeCategory text columns to use enums - Add routes/buffer-rules.ts: GET/POST/PATCH/DELETE, manager role guard - Register /api/buffer-rules in index.ts - Update services.ts PATCH to accept defaultBufferMinutes - Update pets.ts POST/PATCH to accept sizeCategory/coatType - Cast coatType/petSizeCategory in book.ts insert to match new enums - Add 0031_buffer_rules.sql migration - Fix factories.ts buildService to include defaultBufferMinutes: null Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
31 lines
1.8 KiB
SQL
31 lines
1.8 KiB
SQL
-- Migration: 0031_buffer_rules.sql
|
|
-- Buffer rules CRUD: pet size/coat enums, bufferRules table, services.defaultBufferMinutes
|
|
|
|
-- ─── Enums ───────────────────────────────────────────────────────────────────
|
|
|
|
CREATE TYPE "pet_size_category" AS ENUM ('small', 'medium', 'large', 'xlarge');
|
|
CREATE TYPE "coat_type" AS ENUM ('smooth', 'double', 'wire', 'curly', 'long', 'hairless');
|
|
|
|
-- ─── Alter pets columns to use new enums ─────────────────────────────────────
|
|
|
|
ALTER TABLE "pets" ALTER COLUMN "coat_type" TYPE "coat_type" USING "coat_type"::text::"coat_type";
|
|
ALTER TABLE "pets" ALTER COLUMN "pet_size_category" TYPE "pet_size_category" USING "pet_size_category"::text::"pet_size_category";
|
|
|
|
-- ─── Services: add defaultBufferMinutes ───────────────────────────────────────
|
|
|
|
ALTER TABLE "services" ADD COLUMN "default_buffer_minutes" integer;
|
|
|
|
-- ─── Buffer Rules table ───────────────────────────────────────────────────────
|
|
|
|
CREATE TABLE "buffer_rules" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
"service_id" uuid NOT NULL REFERENCES "services"("id") ON DELETE CASCADE,
|
|
"size_category" "pet_size_category",
|
|
"coat_type" "coat_type",
|
|
"buffer_minutes" integer NOT NULL,
|
|
"created_at" timestamp NOT NULL DEFAULT now(),
|
|
"updated_at" timestamp NOT NULL DEFAULT now(),
|
|
CONSTRAINT "uq_buffer_rules_service_size_coat" UNIQUE ("service_id", "size_category", "coat_type")
|
|
);
|
|
|
|
CREATE INDEX "idx_buffer_rules_service_id" ON "buffer_rules"("service_id"); |