Skip to content

Instantly share code, notes, and snippets.

@kmiscia
Last active June 1, 2022 14:25
Show Gist options
  • Save kmiscia/0794f7f7fddf3294e6fc998597578a55 to your computer and use it in GitHub Desktop.
Save kmiscia/0794f7f7fddf3294e6fc998597578a55 to your computer and use it in GitHub Desktop.
-- Seller Timelines
SELECT
timelines.name,
versions.created_at as fell_through_at
FROM
timelines
LEFT OUTER JOIN timeline_fields on timeline_fields.timeline_id = timelines.id
LEFT OUTER JOIN versions ON versions.item_id = timeline_fields.id AND versions.item_type = 'TimelineField'
WHERE
timelines.is_template = FALSE
AND
timelines.rewind_id IS NULL
AND
timelines.type = 'Timelines::SellerTimeline'
AND
timeline_fields.slug = 'status'
AND
versions.event = 'update'
AND
versions.object_changes ->> 'value' = '["Pending", "Active"]'
ORDER BY
versions.created_at DESC;
-- Buyer Timelines
SELECT
timelines.name,
versions.created_at as fell_through_at
FROM
timelines
LEFT OUTER JOIN timeline_fields on timeline_fields.timeline_id = timelines.id
LEFT OUTER JOIN versions ON versions.item_id = timeline_fields.id AND versions.item_type = 'TimelineField'
WHERE
timelines.is_template = FALSE
AND
timelines.rewind_id IS NULL
AND
timelines.type = 'Timelines::BuyerTimeline'
AND
timeline_fields.slug = 'status'
AND
versions.event = 'update'
AND
versions.object_changes ->> 'value' = '["Pending", "Active Search"]'
ORDER BY
versions.created_at DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment