-- Rooms follow-up: constraints + updated_at triggers.

-- A room assignment only makes sense when the asset is at a property.
ALTER TABLE "assets" ADD CONSTRAINT "assets_room_requires_property" CHECK (
	"current_room_id" IS NULL
	OR "current_container_kind" = 'property'
);
--> statement-breakpoint

CREATE TRIGGER property_floors_set_updated_at BEFORE UPDATE ON "property_floors"
	FOR EACH ROW EXECUTE FUNCTION set_updated_at();
--> statement-breakpoint

CREATE TRIGGER property_rooms_set_updated_at BEFORE UPDATE ON "property_rooms"
	FOR EACH ROW EXECUTE FUNCTION set_updated_at();
