-
Notifications
You must be signed in to change notification settings - Fork 187
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
feat(store): add StoreMetadata table for table name and field names #428
Conversation
Can we also add table names? (either here or in another PR) |
I wonder if it'd be better to have a separate |
298b88c
to
b3d643d
Compare
Agree with storing it in a separate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, I like how setMetadata
is an optional extra method now
|
||
// Set metadata | ||
StoreMetadataTable.set(table, tableName, fieldNames); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so clean!
Is the idea here that we'll add |
Is it useful or scary to allow overriding metadata after its already been set? Thinking about the data sync pipeline (events) looking like this:
What should the client do with the second metadata update? Ignore it? Update all values? If code depends on getting |
Yep, it's basically 1 line for me
The schema is immutable, metadata is just names. I imagine client code can initialize names once per session, and then ignore any changes to them. Haven't thought much about it though |
That brings up another question for me: if we're gonna generate some types in the frontend for a given table, and those types depend on field names, and there's multiple events for
These kinds of questions make me wonder if we should make metadata immutable as well, if not required. |
I'd say by default the last one, but we could also let users specify custom overrides (for example if you built a frontend for a third party table that changed it's metadata). Once client definitions for the table exist, the client can also just ignore metadata overrides since they're not relevant for decoding. (The client should probably rely on the auto-generated / statically inferred types to name the schema if they exist to avoid the issues you described). I would assume the rename feature isn't gonna be used too often, but it might be useful in some cases (just like renaming a column in an existing postgres database), so I'd include it by default. |
Another thing I just realized today: MODE will probably need immutable names, otherwise it means a DB migration of column names? Or I guess MODE could store things as fields without names, then separately store the mapping of field indices to names. cc @authcall |
I think since the table metadata is optional and possibly added in a separate transaction than the initial registration of the table, the indexer and client would both have to handle renaming anyway (if dynamically picking up new tables is a feature, which is definitely the case for the indexer but unclear for the client). So it might not be much additional effort to also support renaming again after the first metadata was set? To unblock the network PR work I'd vote for merging this PR as is and possibly add a restriction to being able to modify schema names in a follow up if we the result of our discussion will be that it leads to too much complication too support. |
a00c355
to
d11f911
Compare
I am kinda wondering/leaning towards the client doing the mapping between field name and field index, then do queries under the hood based on only field indices. Then MODE doesn't need to know about field names. |
lgtm
Even with table metadata both the client and MODE could choose to ignore it. |
bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); | ||
bytes memory _newBlob = abi.encodePacked(_blob, bytes(_slice)); | ||
StoreSwitch.setField(_tableId, _primaryKeys, 1, _newBlob); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is autogen but this seems kinda scary for an abi encoded field. I wonder if we should have a per-field way to enable/disable generating push methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it totally does, and it shouldn't be used. string[]
in general is not in a good place rn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this exists for both bytes
and string
(not arrays, just dynamic length things)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's intentional, it's just dangerous when you do abi encoded stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to my original message but I wonder if we should have a per-field way to enable/disable generating push/slice methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not exactly difficult, I think I could make that option very quickly
But it's part of the bigger question of configurability vs simplicity. Currently fields are a simple Record<string, SchemaType>
. Should we make this a shorthand, and allow a field object with various options? I'm kind of leaning yes, but I think I tend to be a bit biased to the configurability side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I have other options in mind that aren't well thought-out yet that could go there too, like enum wrappers)
StoreMetadata
table to store metadata like table name and field names.setMetadata
method toStoreCore
,IStore
andWorld
(with access control based on table ownership)