-- +goose Up -- A device has at most one open location interval: the place it is in now. -- Open intervals are stored with ended_at = started_at and read as ending now. CREATE UNIQUE INDEX activities_open_location_idx ON activities (device_id) WHERE source = 'location' AND attrs ? 'open'; -- +goose Down DROP INDEX activities_open_location_idx;