-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add createdAt
and createdBy
#153
Comments
As @achou11 said on slack, I would say I'm not qualified enough to have a strong opinion.It seems that option 3 is the most efficient/robust but I can't anticipate any shortcomings for it. In terms of implementation, adding those fields on the header seems pretty straightaway. Maybe there's some complexity in grabbing and validating those fields; but maybe if that's the case we can encode both fields in the header AND on the doc for know (so, basically implement (1) and (3)) since we can remove those fields on subsequent versions of the schema. |
Created a quick proof-of-concept for (3) this morning. Seems to make sense. |
createdAt
and createdBy
createdAt
and createdBy
Revisiting this, I'm having second thoughts. Encoding this information to the docId feels too "clever" or "magic", and will either encode a truncated device identifier, or we have massive IDs. I think (1) is nice and simple, and we can use (2) to verify. We can verify at index time, on every read, or within a "validate database" option. We can deal with verification post-MVP. However I would make one change: instead of TL;DR: Recommended plan is to add two fields to common properties for both the protobuf and json schema:
At a later stage we might want to consider parsing the |
Re-thinking and not sure about this again! |
Problem
Clients need to know which device a record was created by, because for some devices (currently mobile, could be based on role later) can only edit records that they created.
Clients need to know when a record was created in order to sort by created date.
createdAt
andcreatedBy
should not be editable.Possible soultions
Store
createdAt
andcreatedBy
in every recordThis is the simplest to implement. Every time a document is updated then these two fields are duplicated to the new version. However there is nothing to stop a "rogue" device changing these fields. However this might be ok, if we are assuming that trusted users are only interacting with the database through the Mapeo Core API, which can enforce that these never change.
Derive
createdAt
andcreateBy
from "root" recordThe indexer could track back to the "root" record (e.g. the version with
links: []
- the record from thecreate()
action).createdBy
can be derived from the hypercore key where this record is written.createdAt
just needs to be trusted. This means a "rogue" client cannot change these fields by updating a document, but it adds more complexity to the indexer. If the "root" record is unavailable (e.g. if the original has not synced for whatever reason) then these fields would be unknown / undefined.Encode
createdAt
andcreatedBy
to thedocId
Reading about snowflake IDs made me think of this. This has the advantage of (2) without the cost of indexing complexity and the problem of missing "root" records. (we still essentially implicitly trust that a
docId
is not changed by an update - but that would effectively create a new document anyway). We currently use 256-bit random numbers for ourdocId
, which is overkill really. 72-bits of entropy with 1 million document IDs would have a 1 in 9.4 billion chance of collision, which seems like plenty - I think worth adding an extra byte over 64-bit, which would have a 1 in 37 million chance of collision with 1 million IDs.Some ways we might implement our IDs:
${random72bits}${deviceID64bits}${timestamp48bits}
so that when a user shares a doc ID externally by only sharing the first few bytes then we can lookup the ID quickly from SQLite index tables via searching for IDs that start with this value.I'm leaning towards option (3), but option (1) might be ok, but we can't change it in the future, so maybe worth encoding this info to docIds anyway?
Related
creatorCoreId
mapeo-sqlite-indexer#7createdBy
andupdatedBy
fields for data returned to client #136The text was updated successfully, but these errors were encountered: