• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed Add-on conflict on upgrade with extending xf_user_option.default_watch_state

Affected version
2.0 Beta 5

Xon

Well-known member
#1
My add-on Thread starter alerts extends xf_user_option.default_watch_state to include a new default state.

It blows up the add-on upgrade process with:
Code:
Running upgrade to 2.0.0 Alpha, step 33...

  [XF\Db\Exception]
  MySQL query error [1265]: Data truncated for column 'interaction_watch_state' at row 908
If I try to create the column myself with:
Code:
ALTER TABLE `xf_user_option`
    ADD COLUMN `interaction_watch_state` ENUM('','watch_no_email','watch_email','watch_op_email') NOT NULL DEFAULT '' AFTER default_watch_state;
I get the error:
Code:
Running upgrade to 2.0.0 Alpha, step 20...
  [LogicException]
  interaction_watch_state already exists in table, but cannot change enum values
What would be the best way to migrate this for users of my add-on without data loss?

So far all I can think of is creating a temporary column before the upgrade, copy the column over, and then patch up after (doing effectively a manual version of step 33). Which is really yuck.
 

Mike

XenForo developer
Staff member
#2
There's another bug report that's somewhat similar, but it's a good example of the danger of changing default columns (particularly enums, though there's an argument that we shouldn't use them in places that we expect people to want to expand; I don't think this is really one of those places though).

So far all I can think of is creating a temporary column before the upgrade, copy the column over, and then patch up after (doing effectively a manual version of step 33).
Well, roughly speaking, something like that would probably be needed, but ideally without changing the default column.
 

Mike

XenForo developer
Staff member
#3
I have actually worked around this. We now only copy values into interaction_watch_state if they're the ones we know about. That should prevent these errors.