coyote-team / coyote

Image annotation site and API to enable the distributed annotation of museum images.
https://coyote-team.github.io/coyote/
Other
58 stars 11 forks source link

Is there a uniqueness constraint on resources? #441

Closed jkva closed 4 years ago

jkva commented 4 years ago

When I create a new resource via the API by posting

{
    "title": "Test",
    "source_uri": "https://www.google.com/url?sa=i&url=https%3A%2F%2Fnl.wikipedia.org%2Fwiki%2FGroucho_Marx&psig=AOvVaw135tY2d7dCS849pHSWUHLJ&ust=1586606863025000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCLDx5qbp3egCFQAAAAAdAAAAABAD",
    "resource_type": "still_image"
}

to

https://staging.coyote.pics/api/v1/organizations/1/resources

I can do this multiple times, each time receiving a 201 CREATED with resource JSON response body. Even though the source_uri is each time the same. Is this by design?

flipsasser commented 4 years ago

There is not a uniqueness constraint, but I think there can be one.

SELECT
  resources.id,
  other.id AS duplicate_id,
  resources.source_uri,
  other.source_uri AS other_uri,
  organizations.title
FROM
  resources
  JOIN organizations ON resources.organization_id = organizations.id
  JOIN resources other ON other.id != resources.id
    AND lower(other.source_uri) = lower(resources.source_uri)
WHERE
  resources.source_uri IS NOT NULL
  AND resources.source_uri != '';

returns 0 results on production. I will have to clear out, like, everything @jkva has done on staging - but hopefully that's okay.

sinabahram commented 4 years ago

Just a note that the constraint should be scoped to an org e.g. an org should only ever have 1 resource with a single URI, even if there are dozens of representations describing that resource, or so I feel.

flipsasser commented 4 years ago

Ah thanks for that @sinabahram - I'll ensure the uniqueness is scoped

flipsasser commented 4 years ago

This is finished and live