Hi,

I have some concerns about schema evolution when refactoring, more specifically when moving a property higher in the hierarchy class.

SUMMARY : I want to move the property 'FirstName' from the class 'Son' to its parents class 'Father'

CODE SAMPLE : (UpgradeHandler included)

// ------------ Old schema -------------
  [HierarchyRoot]
  class Father : Entity  {
    [Field, Key]
    public int Id { get; private set; }
    [Field]
    public string LastName { get; set; }
  }

  class Son : Father  {
    [Field]
    public string FirstName { get; set; }
    [Field]
    public string NickName { get; set; }
  }

// ------------ New schema ------------- : 
// move 'FirstName' from the class 'Son' to its parents class 'Father' :
  [HierarchyRoot]
  class Father : Entity  {
    [Field, Key]
    public int Id { get; private set; }
    [Field]
    public string LastName { get; set; }
    [Field]
    public string FirstName { get; set; }
  }

  class Son : Father  {
    [Field]
    public string NickName { get; set; }
  }

  public class Upgrader : UpgradeHandler  {
    protected override void AddUpgradeHints()  {
      var hintSet = UpgradeContext.Demand().Hints;
      hintSet.Add(
    new CopyFieldHint("Full.Namespace.Son", "Age", typeof(Father), "Age")
      );
    }

PROBLEM : Such an upgrade works perfectly with DomainUpgradeMode.Perform, but fails with DomainUpgradeMode.PerformSafely : Xtensive.Storage.SchemaSynchronizationException: Cannot upgrade schema safely.

Is there any way to perform such a schema evolution in DomainUpgradeMode.PerformSafely mode ? Am I missing something ?

Kind regards,

Auguste


Updated at 04.09.2009 17:37:55

[...] So currently I suggest you a workaround for this: leave source field in model, but apply [Recycled] and [Obsolete] attributes to it. They will ensure appropriate field will be dropped on the last upgrade stage. Hi, thx for your answer. I did try to keep the field in the child class, with Obsolete/Recycled attributes, but the upgrade still works only with DomainUpgradeMode.Perform and fails with DomainUpgradeMode.PerformSafely.

However, it is indeed possible to successfully move a property to the parent class by copying the child property (marked with [Recycled,Obsolete] attribute) to a new property with a different name in the parent class. But, this is NOT possible to do so and keep the same name for the property in the parent class.

Therefore, my workaroud is to upgrade with the following sequence (DomainUpgradeMode.PerformSafely): [] Upgrade no 1 : Copy the property in child class to a new property in the parent class, with a new (temporary) name. Mark [Obsolete, Recycled] the property in the child class [] Upgrade no 2 : Rename the property in the parent class with the correct name.

Are there any plans to support this feature in a single upgrade ?

Best regards,

Auguste

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Sep 03 '09 at 15:54

Auguste's gravatar image

Auguste
25888


One Answer:

The exception is correct: copy hint implies old field must not be removed, but in fact it is. So our schema comparer discovers there is a field it must remove, but since this action was not explicitly hinted, it warns you.

On the other hand, there is no easy way to describe such a field move: rename field hint support renaming in the same class only for now. So currently I suggest you a workaround for this: leave source field in model, but apply [Recycled] and [Obsolete] attributes to it. They will ensure appropriate field will be dropped on the last upgrade stage.


We'll fix the issue with the nearest update. In fact, we must:

  • Provide RemoveFieldHint. This will be definitely done.

  • Possibly, provide MoveFieldHint

  • Fix the issue with copying the field with the same name.

Issue to track: http://code.google.com/p/dataobjectsdot ... ail?id=376

answered Sep 04 '09 at 03:47

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×574

Asked: Sep 03 '09 at 15:54

Seen: 2,019 times

Last updated: Sep 03 '09 at 15:54

powered by OSQA