Skip to content

Conversation

@josephschorr
Copy link
Member

Refactors the code in preparation for storing schema as a singleton and accessing it in that manner

Testing

Unit tests

@josephschorr josephschorr requested a review from a team as a code owner January 6, 2026 21:31
@josephschorr josephschorr requested review from barakmich and removed request for a team January 6, 2026 21:31
@github-actions github-actions bot added area/cli Affects the command line area/api v1 Affects the v1 API area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/dispatch Affects dispatching of requests labels Jan 6, 2026
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 60.71019% with 343 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.57%. Comparing base (8a6d4a9) to head (12ff6ac).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/datastore/mocks/mock_datastore.go 0.00% 154 Missing ⚠️
internal/datastore/schema/schema.go 62.58% 48 Missing and 13 partials ⚠️
internal/datastore/proxy/proxy_test/mock.go 25.00% 24 Missing ⚠️
internal/datastore/proxy/strictreplicated.go 10.00% 18 Missing ⚠️
internal/services/shared/schema.go 63.34% 7 Missing and 4 partials ⚠️
internal/datastore/proxy/checkingreplicated.go 37.50% 10 Missing ⚠️
pkg/schema/resolver.go 60.00% 4 Missing and 4 partials ⚠️
internal/namespace/util.go 72.73% 3 Missing and 3 partials ⚠️
pkg/datastore/errors.go 33.34% 6 Missing ⚠️
internal/testfixtures/validating.go 76.20% 5 Missing ⚠️
... and 18 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

tstirrat15
tstirrat15 previously approved these changes Jan 6, 2026
Copy link
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, see comments

Comment on lines +62 to +64
// 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
Copy link
Contributor

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?

Copy link
Member Author

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

Comment on lines +22 to +23
// RevisionedCaveat is a revisioned version of a caveat definition.
type RevisionedCaveat = RevisionedDefinition[*core.CaveatDefinition]
Copy link
Contributor

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?

Copy link
Member Author

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

Comment on lines +136 to +140
func NewSchemaNotDefinedErr() error {
return SchemaNotDefinedError{
error: errors.New("no schema has been defined; please call WriteSchema to start"),
}
}
Copy link
Contributor

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)
Copy link
Contributor

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)

Comment on lines +1090 to +1099
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
}
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serverless

Comment on lines 49 to 52
// Check if there is any schema defined
if len(namespaces) == 0 {
return "", datastore.NewSchemaNotDefinedErr()
}
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

Comment on lines +198 to +200
// 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.
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api v1 Affects the v1 API area/cli Affects the command line area/datastore Affects the storage system area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants