how to do Magma Class Evolution?

Chris Muller asqueaker at gmail.com
Mon Jan 18 16:12:18 UTC 2010


Hi Bart, class-evolution with Magma is handled like it is with
standard Smalltalk.  Renaming a class works, but you have to be in a
transaction.

Did you happen to review the test, #testClassSchemaUpgrades in the
Magma tester package?  This test shows how a class rename is
accomplished in one quick commit.  If you still have questions about
it after reviewing that, please feel free to ask.

Other types of schema-evolution require one of the approaches you described:

  1) lazy-initialization
  2) bulk upgrade

It used to be that bulk-upgrade could be done directly on the buffers,
but now with the HA function, the best thing to do is to go through
the normal commit channels.

Regards,
  Chris

On Sun, Jan 17, 2010 at 4:24 AM, Bart Gauquie <bart.gauquie at gmail.com> wrote:
> Dear all,
> I'm trying out the Class Evolution features of Magma. Typically you want to
> have following stuff working: rename class, rename field, totally change
> internal structure of some part of the domain. You do this during
> development and have to make sure the data in production database gets
> converted to these new changes.
> I started by testing the 'rename class scenario': You have a running
> production system with a filled database containing objects of a certain
> type. During development, a class is renamed. The first thing I tried was to
> load the package containing the new class type (and not the old type
> anymore) in the production image. As promised on
> http://wiki.squeak.org/squeak/5602, under implementation, Magma recreates
> the old class definition in the production image. However, the objects
> defined in the database are not automatically converted to the new classes.
> (the rename of the class happened in the developer image, not in the
> production image); meaning that if you add new entries, objects of both
> class types will be in the database (which is bad).
> To convert the old classes in database to the new classes, I tried the
> update strategies, as mentioned on http://wiki.squeak.org/squeak/5602.
> Working out the second option: one-shot script to enumerate all instances
> and populate, I followed these steps (my domain is about Productbacklogs,
> sprints and UserStories):
>
> Userstory >> various >> copy: UserStoryOld (make a copy of the old
> UserStory)
> UserStory >> refactor class >> rename: UserStoryNew (give the UserStory the
> new name)
> UserStoryOld >> refactor class >> rename: UserStory (now you have a copy of
> the class definition of production with the old name)
> write a script which converts all entries in the database using UserStory to
> UserStoryNew
>
> UserStory>>asUserStoryNEW
>    |result|
>    result := UserStoryNew new
>    businessvalue: self businessvalue;
>    contents: self contents;
>    title: self title;
>    yourself.
>    resterendeTijdenNodig do: [:each|
>     result addResterendeTijdNodig: each].
>   ^result
>
> and:
>
> a script which iterates over all userstories in the database, creates
> UserStoryNew's from them, makes sure all links from and to the old
> UserStories are replaced by the new ones (for instance: put them in a
> productbacklog, replan them, ...); saving each of them again.
> Load this package in the production image, run the script => all old entries
> are replaced with new classes.
>
> This approach works. It has the advantage that every change is committed,
> you can rollback to a commit point if something fails, and so forth. But it
> takes a lot of time to do such a simple change? Is this what is meant by a
> 'one-shot script to enumerate all instances and populate' ? Is there another
> way of doing this change? Because it would mean that for every rename of a
> class you would have to write such a script.
>
> A field rename can be handled in the same way. Let the old and new field
> coexist, a script iterates over all the objects, copying the old field to
> the new one. If it is just a simple type (Integer, Boolean or String), this
> will be simple again, however if this field is something complex with a lot
> of pointers from and to it, it will become somewhat more difficult to
> correctly write a convert script. But it will be possible.
> According to the wiki there is also 'a faster one-shot script that operates
> directly on the MaObjectBuffers using MagmaFileTraverser'. I looked into
> this, but I did not understand it. Any pointers how to, for instance, do a
> class rename using this technique?
>
> Thanks for any advice,
> Kind Regards,
> Bart
>
> --
> imagination is more important than knowledge - Albert Einstein
> Logic will get you from A to B. Imagination will take you everywhere -
> Albert Einstein
> Learn from yesterday, live for today, hope for tomorrow. The important thing
> is not to stop questioning. - Albert Einstein
> The true sign of intelligence is not knowledge but imagination. - Albert
> Einstein
> However beautiful the strategy, you should occasionally look at the results.
> - Sir Winston Churchill
> It's not enough that we do our best; sometimes we have to do what's
> required. - Sir Winston Churchill
>
> _______________________________________________
> Magma mailing list
> Magma at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/magma
>
>


More information about the Magma mailing list