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

First run/version migration #40

Closed
deanishe opened this issue Oct 16, 2014 · 9 comments
Closed

First run/version migration #40

deanishe opened this issue Oct 16, 2014 · 9 comments

Comments

@deanishe
Copy link
Owner

This is related to #35 in that a version would have to be specified one way or another.

I've run into a problem where a new version of a workflow uses a different settings and cache format to the previous version. Not deleting or updating the old files means the workflow will throw an error.

I could just change the bundle ID and not worry about it, but I'm wondering if this might be a fairly common problem, so would it be worth adding some sort of solution to Alfred-Workflow?

A simple solution may be to add a first_run property to Workflow, which would be True if this particular version of the workflow had never run before. I imagine it would be implemented by checking for the existence of an empty file in the data directory, say, <datadir>/first_run/x.y.z. If it doesn't exist, first_run is True and the file is created. On subsequent runs, first_run would then be False.

That would, however, leave it up to the workflow author to devise whatever system is necessary to guess the format of the old settings/data/cache files and delete or update them as necessary.

Would it therefore be useful to have a kind of "migration framework" where a workflow author can register functions to be called to migrate data between versions, e.g.:

wf = Workflow(version='2.2')

wf.upgrade_manager.register('1.1', '1.2', upgrade_1_1_to_1_2)
wf.upgrade_manager.register('1', '2', upgrade_1_to_2)

Whaddya think?

@fniephaus
Copy link
Contributor

Puh, this already sounds pretty advanced for a helper framework.
I don't think that there's a need for a migration system. I can't think of a scenario where I would really need to know about this.
Besides, I think its a good idea to clear the cache folder after upgrade by default. I haven't tested it yet, but aren't cache and settings deleted automatically after replacing a workflow with a new version?
Keeping settings might be useful but certainly raises the problem of incompatible versions.

@deanishe
Copy link
Owner Author

Certainly the data directory isn't cleared after an update. I think that would be bad form: all your settings gone.

Let's forget about the framework, but I do think the first_run boolean and last_version_run property would be useful: in most cases you wouldn't care if it's the first time v2.1.1 has run if the last version to run was v2.1.0, but you might if it was v1.7, as you may need to clear the caches and/or update the data.

@fniephaus
Copy link
Contributor

Alfred-Workflow could easily clear the caches right before an update is initiated. Developers would have to check their settings in their scripts if they have made changes. Providing a simple first_run() method would make it easier, but that's as far as it should go, right?

@deanishe
Copy link
Owner Author

It'd probably make more sense to have a last_version_run method/property. That'd give you a better idea of whether or not any update may be necessary:

>>> first_run = wf.first_run()
True
# what now?

>>> v = wf.last_version_run()
Version(1.7)
>>> if v < Version('2.0'):
    migrate_v1_to_v2()

@fniephaus
Copy link
Contributor

Sounds about right! :)

@deanishe
Copy link
Owner Author

Of course, it's dependent on some implementation of semantic versioning/version string parsing.

@fniephaus
Copy link
Contributor

True, I thought we already have agreed on semantic versioning for version 2? ;)

@deanishe
Copy link
Owner Author

We had. We have. It will be semantic, but won't implement the full standard because that's rather complex.

@deanishe deanishe added this to the v1.10 milestone Dec 15, 2014
@deanishe
Copy link
Owner Author

Added in v1.10.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants