Problem/Motivation
While Flag is not yet in Beta, this is an issue to track update code for people to use as needed.
Proposed resolution
As update code grows, add it to this issue's summary.
Run 'drush entity-updates'.
$spec = [
'description' => 'The ID of the target entity.',
'type' => 'varchar',
'length' => \Drupal\Core\Entity\EntityTypeInterface::BUNDLE_MAX_LENGTH,
'not null' => TRUE,
];
\Drupal\Core\Database\Database::getConnection()->schema()->changeField('flagging', 'flag_id', 'flag_id', $spec);
TODO: the issue also adds an index to the table; update code should add this too.
Comments
Comment #2
jhedstromThis is the update code for #2678756: Allow config entities to be flagged.
Comment #3
jibranI think we can improve it by addressing #2678756-77: Allow config entities to be flagged.
Comment #4
joachim commentedThanks for filing this :)
Though I would just post the code as plain PHP to be run by Drush, and post it in the issue summary rather than a file. We definitely do not want people to run this code as update hooks, as then they won't be able to run a future, real update 8001 without hacking their site state.
Comment #5
joachim commentedSchema module is really useful for doing this sort of thing -- however, the D8 version is on github and needs a few tweaks to get it working: #2334557: Drupal 8 Version.
Adding partial update code for #2845567: make use of ContentEntityBase::baseFieldDefinitions(); make flag_id an entity reference field.
Comment #6
joachim commentedComment #7
joachim commentedNot sure why the code for #2845567: make use of ContentEntityBase::baseFieldDefinitions(); make flag_id an entity reference field isn't working.
On the one hand, it appears to change the database structure. But when I run 'drush entity-updates' to deal with an unrelated update, I get this error:
Comment #8
kovtunos commentedGot this error too. Is there a way to fix this without reinstall the module?
Comment #9
berdir> Not sure why the code for #2845567: make use of ContentEntityBase::baseFieldDefinitions(); make flag_id an entity reference field isn't working.
Because you just change the database schema, but you didn't tell the entity definitions update manager that you did so.
See for exampe poll_update_8001(). you need to load the generated/stored sql schema and field definitions and update that as well.
I still don't quite understand why you're against adding update functions, you'll likely spend more time on closing/answering support requests than maintaining those and I would even write them as I mentioned once, because I eventually will have to do that anyway for our projects. But currently I'm simply waiting until the first beta.
The problem is that many projects provide updates in alpha versions (including most that I maintain, at least big ones like redirect) so it's hard for users to figure out when they can use an alpha and when not. Also, flag is taking its time to get out of the alpha phase ;)
Comment #10
fgmBased on @berdir 's suggestion, here is a hook_update() I did in my site module, and which looks like it could become flag_update_80xx(). It prevents the error when doing a second drush entup, which happens with just the current version of flag:
If it runs in a drush updb before drush entup, the second drush entup doesn't fail like it does with just flag module enabled.
Any ideas for improvements ?
Comment #11
joachim commented> I still don't quite understand why you're against adding update functions, you'll likely spend more time on closing/answering support requests than maintaining those and I would even write them as I mentioned once, because I eventually will have to do that anyway for our projects. But currently I'm simply waiting until the first beta.
Because then it wouldn't be an alpha any more, because users would have the expectation that we'd fix all of their breakages, such as changes to their views and so on. I am tempted to just say, 'what the hell, if people file hook_update_N() patches then I will commit them blindly' but then I don't want that to lead to issues that break stuff getting held up with writing the updates, and then some changes get updates and some don't, and we still have problems with expectations.
That said, looking at the beta blockers in issue queue, I think we're done with schema-breaking things, it's just API-breaking things from here on. Which is going to lead to even more support requests, as people don't read the release notes (me included, if I'm honest...) and we can't do updates that rewrite people's code...
> you'll likely spend more time on closing/answering support requests than maintaining those
You're thinking it's the same kind of time, but it's not. I can rattle off a reply to a support request at 07:50 on the tablet while I'm waiting for my 2-year-old to come downstairs for breakfast, but I can't do any coding in that length of time. I can do issue triage at 21:00 when the kids are in bed and I'm exhausted and watching wallpaper television, but I don't have the mental energy to fix bugs.
> Also, flag is taking its time to get out of the alpha phase ;)
Yeah... :( Flag 4.x as it stands still feels like it's only doing about 50% of what 3.x does. I am sometimes sorely tempted to just take 3.x, do the bare minimum to get it working on Drupal 8, and release that, and then gradually add bits of 4.x into it. I honestly don't know at this point what would be the quickest path to a stable release.
Comment #12
kgaut commentedHi,
So i guess I'm stuck too :)
@fgm's update function in #10 works fine and allows me to update / create my custom entity type.
Cheers !
Comment #13
jochemvn commentedHi fgm,
I'm curious to know what commit did you write this update hook on? I'm currntly on this one: "http://cgit.drupalcode.org/flag/commit/?h=8.x-4.x&id=4f9093a3da47d95dae1...". It doesn't seem to work for our Open Social Distro. The hook is being executed and it says everything went fine, but still a drush entup gives me:
Any clue? Help would be much appreciated
Comment #14
kgaut commentedHi jochemvn,
yep after the update, drush entup still gave flagging entity type to update, but this time, it wont fail (at least it did not on my install)
regards
Comment #15
fgm@jochemvn: like @kgaut implied, you need to run entup /twice/ after this hook to get the update to be complete. Since it never hurts to do it anyway, I actually always run it thrice in my CI update jobs.
A better update hook could probably avoid this step, but it's sufficient for now until an actual update path is validated by @joachim.
Comment #16
damienmckennaAnother +1 for the update script in #10, it solved the problems I was running into after updating from alpha1 to either alpha2 or the latest -dev snapshot.
Comment #17
damienmckennaThe update script from #10 in patch format.
Comment #18
socketwench commentedNow that the patch is in the right form, I think there's enough above for this to be RTBC.
Comment #20
socketwench commentedThanks everyone!
Comment #22
larowlanI'm still seeing entity-update issues on 8.7 even though this update hook ran
`Flagging: The Flag field needs to be updated.`
should I open a new issue or happy to continue here?
Comment #23
larowlanMy definitions and what's in the kv look good
KV:
Table def:
Indexes:
And the character set on that column is ascii
Comment #24
a.dmitriiev commentedI am not sure if 2 years ago "entity.definition_update_manager" and "entity_field.manager" services exist, but they were there for sure since 8.2, but I think the update 8401 should be something like in the attached patch. I have incremented the update number of course up to 8402.
Comment #25
a.dmitriiev commentedMade a typo in \Drupal. Here is the updated patch
Comment #26
a.dmitriiev commentedComment #27
berdirI suggest you create a new issue, nobody is going to look at this :)
Saw the notification but will have forgotten about this in a minute again.
Comment #28
pawel_r commented#25 Solved issues in my case (Drupal 8.8, FLag 4.0 beta1).