Skip to content

Add version to block script data #122

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

Merged
merged 1 commit into from
Jul 10, 2024
Merged

Conversation

manuq
Copy link
Contributor

@manuq manuq commented Jul 8, 2024

@manuq manuq requested a review from dylanmccall July 8, 2024 13:31
@manuq manuq force-pushed the T35547-add-version-to-data branch from 8acf1f2 to e298518 Compare July 8, 2024 13:35
@dbnicholson
Copy link
Member

I very much like this idea, but I think we may not want to use the actual plugin version in the script. Instead, I think we should maintain a separate data version. Since the data format won't change with every plugin release, we don't need to attempt migration. This would also handle a development snapshot since the data version could be bumped independently of the plugin version.

The data version could be a simple integer counter that we bump whenever the data format changes. We'd set that to 1 now and any script that does not have a version is treated as 0. I don't think we'd need point releases as the semantics would always be to migrate the data to the current version regardless of what it previously was..

@manuq manuq force-pushed the T35547-add-version-to-data branch from e298518 to 1e59756 Compare July 10, 2024 12:57
@manuq
Copy link
Contributor Author

manuq commented Jul 10, 2024

@dbnicholson good points. I addressed the comments and force-pushed.

Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

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

This is a good start. I think it might end up changing form when we actually try to tackle migration, but this gets the basic data in place.

if version == Constants.CURRENT_DATA_VERSION:
# No migration needed.
return
push_warning("Migration not implemented from %d to %d" % [version, Constants.CURRENT_DATA_VERSION])
Copy link
Member

Choose a reason for hiding this comment

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

I think this is good enough for now, but in the future we might want to beef this up. If the stored data version is less than the current data version, migrate it. If the stored data version is greater than the current data version, then someone has already migrated the data to a newer plugin version and is now trying to run an older version of the plugin. Since the older plugin version by definition doesn't know about the newer data format, I think the only thing to do there would be to refuse to load the script and bring up some kind of error message.

@@ -129,6 +141,7 @@ func save_script():
var generated_script = _block_canvas.generate_script_from_current_window(block_script.script_inherits)
block_script.block_trees = block_trees
block_script.generated_script = generated_script
block_script.version = Constants.CURRENT_DATA_VERSION
Copy link
Member

Choose a reason for hiding this comment

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

Can we arbitrarily update the version in the saved script if it hasn't been migrated? This is probably fine for now but eventually I'd expect save_script to bail if _current_block_code_node.version != Constants.CURRENT_DATA_VERSION. Maybe generate_script_from_current_window is the one doing the heavy lifting there and should return null if it can't understand the blocks on screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is TBD. I guess we'll try a migration and if that fails the blocks shouldn't be editable at all, can't be saved.

@@ -1,5 +1,7 @@
extends Object

const CURRENT_DATA_VERSION = 1
Copy link
Member

Choose a reason for hiding this comment

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

Backtracking on my earlier thought, I wonder if this should still be 0 since we haven't changed the serialization yet. #107, for example, would bump this up. Or we just keep it 0 until we're ready to handle stability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's keep it zero until we are ready to handle migrations.

In the plugin, add a new constant for the current data version. This
will start in 0 and be bumped each time the data format changes.

In the BlockScriptData resource, add an integer version field which
defaults to zero. The version will be set to the current version when
the resource is saved.

The actual migration is TBD. Only a warning is printed for now.

https://phabricator.endlessm.com/T35547
@manuq manuq force-pushed the T35547-add-version-to-data branch from 1e59756 to 20f5f54 Compare July 10, 2024 18:02
Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

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

Looks good now. Merging.

@dbnicholson dbnicholson merged commit 387f5ca into main Jul 10, 2024
2 checks passed
@dbnicholson dbnicholson deleted the T35547-add-version-to-data branch July 10, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants