Skip to content

Instantly share code, notes, and snippets.

@atz
Created June 26, 2018 00:34
Show Gist options
  • Save atz/f2df4c950325d1f483264a42857830c5 to your computer and use it in GitHub Desktop.
Save atz/f2df4c950325d1f483264a42857830c5 to your computer and use it in GitHub Desktop.
query logic
Endpoint.which_need_archive_copy("bj102hs9687",2)
SELECT "endpoints".* FROM "endpoints"
INNER JOIN "endpoint_types" ON "endpoint_types"."id" = "endpoints"."endpoint_type_id"
INNER JOIN "endpoints_preservation_policies" ON "endpoints_preservation_policies"."endpoint_id" = "endpoints"."id"
INNER JOIN "preservation_policies" ON "preservation_policies"."id" = "endpoints_preservation_policies"."preservation_policy_id"
INNER JOIN "preserved_objects" ON "preserved_objects"."preservation_policy_id" = "preservation_policies"."id"
WHERE "endpoint_types"."endpoint_class" = $1
AND "preserved_objects"."druid" = $2
AND (NOT (EXISTS (
SELECT "preserved_copies".* FROM "preserved_copies"
WHERE ("preserved_copies"."endpoint_id" = "endpoints"."id"
AND "preserved_copies"."version" = 2
)))) [["endpoint_class", "archive"], ["druid", "bj102hs9687"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment