Skip to content

Allow layout-altering automigrations of event tables#5269

Merged
joshua-spacetime merged 7 commits into
masterfrom
phoebe/automigrate-event-tables
Jun 11, 2026
Merged

Allow layout-altering automigrations of event tables#5269
joshua-spacetime merged 7 commits into
masterfrom
phoebe/automigrate-event-tables

Conversation

@gefjon

@gefjon gefjon commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description of Changes

This commit adds special handling in automigrations to accept a broad set of schema- and layout-altering automigrations on event tables, including changes that we'd reject for non-event tables like removing or reordering columns, or layout-incompatibly changing the types of existing columns.

This is due to a change we want to make to the ControlDB schema, where we have a product type which is used both as a table type, and as the column type of an event table, and we want to add an element to that product type.

I've added a simple smoketest of the new behavior, automigrate_reschema_event_table_arbitrarily. Note that I have not tested commitlog replay of a database which has undergone one of these migrations, which has been a common place that bugs have appeared in similar changes in the past.

I have done a pretty lazy job with the migration plan formatter for the new step, just printing the name of the event table which is changing, not any information about the specific changes or the columns. This is in an effort to save time, as we'd like to release the ControlDB change blocked by this.

API and ABI breaking changes

N/a

Expected complexity level and risk

3 at least: new categories of automigrations have a high risk to introduce commitlog replay bugs, and it's also possible I have misunderstood or mis-remembered some of the safety invariants of the table crate.

Testing

  • New (minimal) smoketest.
  • Manually tested replay:
    • Copied event table from the before version new smoketest into module-test.
    • Published module-test.
    • Replaced event table with after version, published, observed and approved client-breaking automigration.
    • Restarted SpacetimeDB.
    • Called the procedure return_value in the migrated module to force commitlog replay.
  • Test the ControlDB change in staging, incl. restarting the control node.

This commit adds special handling in automigrations to accept
a broad set of schema- and layout-altering automigrations on event tables,
including changes that we'd reject for non-event tables like removing or reordering columns,
or layout-incompatibly changing the types of existing columns.

This is due to a change we want to make to the ControlDB schema,
where we have a product type which is used both as a table type,
and as the column type of an event table,
and we want to add an element to that product type.

I've added a simple smoketest of the new behavior,
`automigrate_reschema_event_table_arbitrarily`.
Note that I have not tested
commitlog replay of a database which has undergone one of these migrations,
which has been a common place that bugs have appeared in similar changes in the past.

I have done a pretty lazy job with the migration plan formatter for the new step,
just printing the name of the event table which is changing,
not any information about the specific changes or the columns.
This is in an effort to save time, as we'd like to release the ControlDB change blocked by this.
@gefjon gefjon requested a review from joshua-spacetime June 10, 2026 17:57

@joshua-spacetime joshua-spacetime left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a commitlog replay test for this? In particular replay from snapshot?

@gefjon

gefjon commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Can we add a commitlog replay test for this? In particular replay from snapshot?

I am not sure how we would do that. To my knowledge, we don't currently have any tests of commitlog replay, or any infrastructure for testing it.

joshua-spacetime and others added 3 commits June 10, 2026 12:38
Tested manually by doing the same automigrations as in the smoketest,
then restarting the database and calling a procedure in the migrated database
to force replay.
…klabs/SpacetimeDB into phoebe/automigrate-event-tables
@gefjon

gefjon commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

I have not added an automated test of replay, but I tested it manually, and it worked after my latest commit.

@joshua-spacetime joshua-spacetime added this pull request to the merge queue Jun 11, 2026
Merged via the queue into master with commit ca16958 Jun 11, 2026
32 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