-- Custom SQL migration file, put your code below! -- CREATE TABLE "pets" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "household_id" uuid NOT NULL, "name" text NOT NULL, "species" text NOT NULL, "breed" text, "birth_date" date, "notes" text, "primary_image_url" text, "images" jsonb DEFAULT '[]'::jsonb NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "pets_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action ); --> statement-breakpoint CREATE TABLE "pet_appointments" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "pet_id" uuid NOT NULL, "household_id" uuid NOT NULL, "title" text NOT NULL, "appointment_at" timestamp with time zone NOT NULL, "clinic" text, "notes" text, "calendar_event_id" uuid, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "pet_appointments_pet_id_pets_id_fk" FOREIGN KEY ("pet_id") REFERENCES "public"."pets"("id") ON DELETE cascade ON UPDATE no action, CONSTRAINT "pet_appointments_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action ); --> statement-breakpoint CREATE TABLE "pet_vaccinations" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "pet_id" uuid NOT NULL, "household_id" uuid NOT NULL, "name" text NOT NULL, "administered_on" date NOT NULL, "due_on" date, "provider" text, "notes" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "pet_vaccinations_pet_id_pets_id_fk" FOREIGN KEY ("pet_id") REFERENCES "public"."pets"("id") ON DELETE cascade ON UPDATE no action, CONSTRAINT "pet_vaccinations_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action ); --> statement-breakpoint CREATE TABLE "pet_prescriptions" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "pet_id" uuid NOT NULL, "household_id" uuid NOT NULL, "medication" text NOT NULL, "dosage" text NOT NULL, "instructions" text, "prescribed_on" date, "expires_on" date, "refills_remaining" integer, "active" boolean DEFAULT true NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "pet_prescriptions_pet_id_pets_id_fk" FOREIGN KEY ("pet_id") REFERENCES "public"."pets"("id") ON DELETE cascade ON UPDATE no action, CONSTRAINT "pet_prescriptions_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action ); --> statement-breakpoint CREATE INDEX "pets_household_idx" ON "pets" USING btree ("household_id"); --> statement-breakpoint CREATE INDEX "pet_appointments_pet_at_idx" ON "pet_appointments" USING btree ("pet_id", "appointment_at"); --> statement-breakpoint CREATE INDEX "pet_vaccinations_pet_due_idx" ON "pet_vaccinations" USING btree ("pet_id", "due_on"); --> statement-breakpoint CREATE INDEX "pet_prescriptions_pet_active_idx" ON "pet_prescriptions" USING btree ("pet_id", "active");