Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dataType.delete() should use docId not versionId #422

Closed
gmaclennan opened this issue Dec 18, 2023 · 3 comments · Fixed by #424
Closed

fix: dataType.delete() should use docId not versionId #422

gmaclennan opened this issue Dec 18, 2023 · 3 comments · Fixed by #424
Assignees

Comments

@gmaclennan
Copy link
Member

Description

Reading through #420 made me realize that I think our current delete() method does not make sense. Trying to "delete" an arbitrary version of a doc doesn't actually do anything unless it is a "head". It will actually create a fork, which is kind of confusing.

e.g. we have a doc with docId X, created with versionId A. It is then edited so we have version B. Now a user tries to delete version A. They will create a new version C, and we now have two "heads" or "forks": B and C.

I think the delete method should actually accept the docId, since what you actually expect from deletion is that the document is no longer returned from getMany(). The delete function should:

  1. Get the existing doc for that docId, and get the versionId
  2. Check the forks property, and also get the existing doc(s) for those forks, to get the versionIds
  3. Create a doc with deleted: true that has links with the versionIds above.
  4. For the document data that is written to the delete doc, use the value from (1) (e.g. the doc that would be returned from dataType.getByDocId(docId).

@achou11 @tomasciccola thoughts or comments?

@gmaclennan
Copy link
Member Author

This could raise the question, "how do I delete a fork", which you do as:

const obs = await project.observation.getByDocId(docId)
const merged = await project.observation.update([obs.versionId, ...obs.forks], valueOf(obs))

Could look at creating a helper for this in the API if needed once we introduce a UI for managing forks.

@achou11
Copy link
Member

achou11 commented Dec 18, 2023

yeah i think this makes sense. So basically:

  • DataType.delete() is reserved for deleting the latest locally known version of a record
  • if needed, you could technically use DataType.update() to delete an older version or delete a fork?

@gmaclennan
Copy link
Member Author

yeah, although "deleting an older version" and "deleting a fork" doesn't really have a clear meaning.

@gmaclennan gmaclennan self-assigned this Dec 19, 2023
gmaclennan added a commit that referenced this issue Dec 19, 2023
Fixes "`dataType.delete()` should use `docId` not `versionId`" (#422)

The deletion document links to all forks, if forks exist.
@gmaclennan gmaclennan linked a pull request Dec 19, 2023 that will close this issue
gmaclennan added a commit that referenced this issue Dec 19, 2023
* fix!: delete() by docId not versionId(s)

Fixes "`dataType.delete()` should use `docId` not `versionId`" (#422)

The deletion document links to all forks, if forks exist.

* Remove comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants