Skip to content

Remove module update functionality in favor of future migration/publish argument implementation #1370

@cloutiertyler

Description

@cloutiertyler

Callback when publishing without -c

Problem

The BitCraft team wants some custom logic to execute when they publish a module without using -c. One thing Alexander wants to be able to do is change the duration of a scheduled reducer (because the durations are part of the static data, which they can update from the client).

Proposed Solution #1

We could add a callback function that is analogous to the init(..) function, except its executed when publishing without -c. Basically in this new update(..) function he could lookup any scheduled reducers, cancel them all, and then reschedule them with the new updated value.

Perhaps we decorate like this:

#[spacetimedb(init)]
pub fn init() {
  // Do stuff in here that should only be done when starting from scratch
}

#[spacetimedb(update)]
pub fn update() {
  // Do stuff in here that should be done when starting from scratch *or* when a module is updated
}

This solution is in the same vein as a migration handler. As specified here this function would not have any ability to migrate any data, but it would give you a handle to be able to do operations on your module

Some questions to answer before we move forward on this:

  • As part of the module lifecycle, maybe init is called when you publish with -c and module_updated(..) is also called when you publish with -c, but when you publish without -c only module_updated(..) is called.

Proposed Solution #2

(pasted from comments section)

For now we could just tell the BitCraft team to refactor their code. Any code that manages repeating reducers should be in a new reducer called manage_reducers(..) . This reducer would be called from init, but it would also be manually invoked after publishing without -c.

This ticket is about number 1 here:*

  1. You haven’t changed the schema and you’re intending to update the module and you want to run something when that happens
  2. You have changed the schema, but you haven’t written a migration function. If we continue with this you will be in a borked state so we should throw an error
  3. You want to do a migration, you’ve done a schema change and you’ve written a migration function.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions