-
Notifications
You must be signed in to change notification settings - Fork 363
Prepare for single stored schema #2805
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
base: main
Are you sure you want to change the base?
Conversation
…gacy Will allow for easy replacement in the followup commit
…n the legacy methods
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2805 +/- ##
==========================================
- Coverage 77.71% 77.57% -0.14%
==========================================
Files 472 473 +1
Lines 49709 50047 +338
==========================================
+ Hits 38627 38819 +192
- Misses 8231 8363 +132
- Partials 2851 2865 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tstirrat15
left a comment
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, see comments
| // AddDefinitionsForTesting adds or overwrites the given schema definitions. This method is | ||
| // only for use in testing and requires a testing.TB instance to enforce this constraint. | ||
| AddDefinitionsForTesting(ctx context.Context, tb testing.TB, definitions ...SchemaDefinition) error |
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.
This seems like a sane way to do this that i wouldn't have thought of. Is there a reason that it's a part of the interface rather than something that each concrete type defines its own instance of?
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 that tests can operate on it without having to know to which impl they are talking, e.g. for the generic datastore tests
| // RevisionedCaveat is a revisioned version of a caveat definition. | ||
| type RevisionedCaveat = RevisionedDefinition[*core.CaveatDefinition] |
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.
Why is this one in legacy but the other one is in schema? Will caveats be handled differently under the new system?
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.
History - I plan to move over the legacy one after this PR when the new impl goes in
| func NewSchemaNotDefinedErr() error { | ||
| return SchemaNotDefinedError{ | ||
| error: errors.New("no schema has been defined; please call WriteSchema to start"), | ||
| } | ||
| } |
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.
Nice.
| return nil, ss.rewriteError(ctx, err) | ||
| } | ||
|
|
||
| caveatDefs, err := reader.ListAllCaveats(ctx) |
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 like the way this simplifies (knowing that there's more of this to come)
| for _, def := range foundDefs { | ||
| if nsDef, ok := def.(*core.NamespaceDefinition); ok { | ||
| newDef, err := schema.NewDefinition(ts, nsDef) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| loadedNamespaces[nsDef.Name] = newDef | ||
| } else if caveatDef, ok := def.(*core.CaveatDefinition); ok { | ||
| loadedCaveats[caveatDef.Name] = caveatDef | ||
| } |
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.
This probably isn't a "now" problem, but if we're going to upstream things like partials into the main schema DSL, will this logic need to change? Or are we only storing materialized definitions in the database and we'll say that users can't write a schema with partials?
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.
We're not going to allow partials in "final" schemas - it will have to be complied before hand
| // as that is handled by the ensureNoRelationshipsExistWithResourceType call above. | ||
| if removedObjectDefNames.Len() > 0 { | ||
| if err := rwt.DeleteNamespaces(ctx, removedObjectDefNames.AsSlice(), datastore.DeleteNamespacesOnly); err != nil { | ||
| // Write the new/changes caveats. |
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.
| // Write the new/changes caveats. | |
| // Write the new/changed caveats. |
| } | ||
| if validated.additiveOnly { | ||
| // DEPRECATED: Use of legacy methods for additive-only schema changes is deprecated. | ||
| // This path is maintained for backwards compatibility but will be removed in a future version. |
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.
What's the backwards compatibility in question here?
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.
Serverless
internal/datastore/schema/schema.go
Outdated
| // Check if there is any schema defined | ||
| if len(namespaces) == 0 { | ||
| return "", datastore.NewSchemaNotDefinedErr() | ||
| } |
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.
Nit, but this can go above the above block
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.
Moved
| // future use but is currently ignored by implementations. The method validates that no | ||
| // definition names overlap, loads existing definitions, replaces changed ones, and deletes | ||
| // definitions no longer present. |
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.
Is it implicit that all of this is happening within the same transaction?
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.
The writer is defined on the transaction, so yes
fd8f3a7 to
12ff6ac
Compare
tstirrat15
left a comment
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
Refactors the code in preparation for storing schema as a singleton and accessing it in that manner
Testing
Unit tests