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

Rework RLS macro for amended syntax #2105

Merged
merged 7 commits into from
Jan 14, 2025
Merged

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Jan 10, 2025

Description of Changes

Out-of-band discussion resulted in a different syntax for registering RLS rules in module code. This PR implements that new syntax in Rust modules. C# modules, which did not have an implementation prior, are unaffected.

The new macro's implementation is significantly simpler, with all the interesting work done by "runtime" code rather than in the macro. One effect of this is that SQL syntax errors are no longer detected at compile time. Instead, they will only be checked at spacetime publish time, when the filter query is processed by the SpacetimeDB host. I consider this reasonable, as even in the previous design, most "interesting" errors (e.g. name resolution, type checking) could only be detected at publish time anyways. The new macro could perform SQL syntax checking in the same way as the old one, but I consider the benefits of this to be outweighed by the added complexity in our macro code it would require.

This commit also applies #[doc(hidden)] to everything RLS-related, with TODO comments to make them visible once RLS is fully implemented.

API and ABI breaking changes

No, in the sense that RLS is not actually implemented, and so no one could possibly have been depending on it.

Expected complexity level and risk

1: new macro is much simpler; internals are unchanged.

Testing

  • Updated smoketests and SDK test module to use the new macro syntax. The smoketest makes assertions about the resulting system tables.
  • It's essentially impossible to do any more testing, as RLS is not implemented, so this macro doesn't actually do anything currently.

Out-of-band discussion resulted in a different syntax
for registering RLS rules in module code.
This PR implements that new syntax in Rust modules.
C# modules, which did not have an implementation prior, are unaffected.

The new macro's implementation is significantly simpler,
with all the interesting work done by "runtime" code rather than in the macro.
One effect of this is that SQL syntax errors are no longer detected at compile time.
Instead, they will only be checked at `spacetime publish` time,
when the filter query is processed by the SpacetimeDB host.
I consider this reasonable, as even in the previous design,
most "interesting" errors (e.g. name resolution, type checking)
could only be detected at publish time anyways.
The new macro could perform SQL syntax checking in the same way as the old one,
but I consider the benefits of this to be outweighed
by the added complexity in our macro code it would require.

This commit also applies `#[doc(hidden)]` to everything RLS-related,
with TODO comments to make them visible once RLS is fully implemented.
Prior to this commit, `DESCRIBERS` was a vec of function pointers.
This meant that each `DESCRIBER` needed to be its own function,
rather than a closure over the thing being described.

With this commit, `DESCRIBERS` is amended to hold boxed closures.
This allows `register_row_level_security` to operate without a type parameter.
Copy link
Contributor

@mamcx mamcx left a comment

Choose a reason for hiding this comment

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

LGTM

gefjon and others added 2 commits January 14, 2025 16:03
Co-authored-by: joshua-spacetime <[email protected]>
Signed-off-by: Phoebe Goldman <[email protected]>
Co-authored-by: joshua-spacetime <[email protected]>
Signed-off-by: Phoebe Goldman <[email protected]>
@gefjon gefjon enabled auto-merge January 14, 2025 21:04
@gefjon gefjon added this pull request to the merge queue Jan 14, 2025
Merged via the queue into master with commit dc0bdce Jan 14, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants