SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Pretty print auto-migration plans

Open kazimuth opened this issue 11 months ago • 5 comments

Description of Changes

Implements https://github.com/orgs/clockworklabs/projects/22/views/16?filterQuery=migration&pane=issue&itemId=91111218.

While implementing this, I discovered auto-migration plans applied their steps in a nondeterministic order (I was iterating a hashmap and had forgotten to sort.)

This interacted in a particularly bad way with row-level-security policies:

  • Row level security policies are removed and re-added in every automigration, to allow the core crate to re-initialize the relevant queries. (I disagree with this -- it should be an implementation detail of the core crate, not mentioned in auto-migrations -- but I'm not changing it in this PR; see my comments about it in the code.)
  • Since ordering was random, the Add step for the policy could be run before the Remove step.
  • Adding an already existing policy was implemented in an idempotent way by the core crate.
  • So, any auto-migration could nondeterministically drop row-level-security policies!

This is now fixed by simply sorting the steps of an auto-migration in a prescribed way.

API and ABI breaking changes

This is a minor breaking change to the client API since it adds data to the result of an update call.

Expected complexity level and risk

0

Testing

Added a smoketest. TODO: I want to add to the integration tests of the schema crate as well.

kazimuth avatar Dec 16 '24 21:12 kazimuth

Please separate the bugfix from the new feature. These should be separate PRs.

gefjon avatar Jan 09 '25 21:01 gefjon

Sure, https://github.com/clockworklabs/SpacetimeDB/pull/2104

kazimuth avatar Jan 09 '25 21:01 kazimuth

Not my place but:

This is a minor breaking change to the client API since it adds data to the result of an update call.

Is that a breaking a change? It sounds purely additive, which I would've called not-api-breaking?

bfops avatar Jan 13 '25 18:01 bfops

Converting to draft per https://github.com/clockworklabs/SpacetimeDB/pull/2065/files#r1910890326

bfops avatar Jan 13 '25 18:01 bfops

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 03 '25 18:05 CLAassistant