Problem/Motivation

@catch said there might be an old issue for this, but I couldn't find it. We're already up to hook_update_N() in the range of 8500+ with the naming convention of major and minor on the first two digits. With the current release schedule, we'll be out of the four-digit range in two years. Kind of like a Y2K bug for update hooks.

Proposed resolution

Figure out how to handle this situation and update our policy, the hook documentation, and/or core.

  • If we have an 8.10.x, should its update hooks start with hook_update_81001()? What happens if you have a five-digit update hook? drupal_get_schema_versions() doesn't seem to specifically limit it to four digits.
  • If we do start defining five-digit update hooks for Drupal 8, will that wreak havoc with schema versions when Drupal 9 comes out? The current checks to inform D7 users that they need to migrate instead of update do a less than comparison. 81001 is not less than 9000. A workaround might be that 9.x needs to just start with a schema version of 90000.
  • And then the problem starts over again if we number 9.x's update hooks as 91000 for Drupal 9.1, 92000 for Drupal 9.2, etc.

Remaining tasks

TBD

Data model changes

Comments

xjm created an issue. See original summary.

xjm’s picture

xjm’s picture

Issue summary: View changes
xjm’s picture

Issue summary: View changes
dawehner’s picture

This is a really interesting problem!

I was thinking for a second about splitting up the version numbers: system_update_8_6_20. Looking at \drupal_get_schema_versions and \update_get_update_function_list it seems to be possible to allow both kind of number schemes, while keeping a custom sort function around.

jepster_’s picture

Since the hook_update_N() system is very old and we want to switch more and more to events: How about introducing an event for updates? The event listener would have a version, which would be applied into the database. That way we could mark hook_update_N() as deprecated.

xjm’s picture

@plach, @catch, @larowlan, @effulgentsia, and I discussed this issue today. We agreed it should be critical; we need to have a way of solving it.

For #6 I think it's a good idea to explore in the long term, but we should have a minimal fix for the immediate issue first. #5 sounds like a reasonable way to accomplish that minimal fix. We'd probably want to have a bunch of test cases to confirm that various schema versions are correctly interpreted as being older, newer, or the same as each other. (And "the same as" is an interesting edge case.)

xjm’s picture

Issue tags: +Triaged D8 critical
jacktonkin’s picture

I haven't looked at the code, but isn't the simplest thing to do what the Issue Summary suggests for 8.10.x (go to 5-digit schema versions), but then to keep 5 digits for Drupal 9, numbering 9.1.x updates from 90100, and so on?

berdir’s picture

Yeah, what #9 said. the update system only cares about one thing.. storing the last-updated number and then running all updates with a bigger number. We could have a number like 81456444, the update system couldn't care less, as long as the 9.x updates will use the same amount of digits/be an even bigger number.

I think this is basically non-issue, worst case is we have to update some documentation if we actually have to do this :)

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new4.19 KB

Let's see whether this test passes.

Status: Needs review » Needs work

The last submitted patch, 12: 2924725-12.patch, failed testing. View results

xjm’s picture

Edit: never mind, what I said made no sense. Carry on.

berdir’s picture

@xjm: Only in case 10k update functions wouldn't be enough for 9.x :) But I see you already edited your comment, still got the see the old one thanks to e-mail notifications ;)

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new3.58 KB
new3.42 KB

That was certainly an "interesting" use of the state API @dawehner :)

Rerolled, removed the unrelated part so it applies and also added a second part that makes sure additional update functions are executed/not executed as expected.

Since this just adds test coverage for something that works fine, I don't think it needs to be critical. As mentioned above, beside the test coverage, the only thing we probably need is adjusted documentation once/if we reach 8.10 but that too doesn't seem critical.

dawehner’s picture

Priority: Critical » Major
Status: Needs review » Reviewed & tested by the community

Yeah I call it poormans-backtrace.

+++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php
@@ -94,4 +94,31 @@ public function testUpdateHookN() {
+    // Ensure that 810002 was executed but 8302 was not since we were already
+    // past that number.
+    $this->assertEquals(['update_test_schema_update_8002', 'update_test_schema_update_8301', 'update_test_schema_update_810001', 'update_test_schema_update_810002'], \Drupal::state()->get('update_test_schema_high_schema'));

Nice additional test coverage. I also like these kind of explanation comments!

I agree its not critical, given we figured out it actually works.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Maybe let's just patch the docs now? Including documenting how they'll be numbered in D9.

berdir’s picture

@xjm: I'm not sure. For now, nothing changes. If we never reach 8.10, nothing will change, not for 8.x.

It seems rather abstract to document that theoretical possibilty now if it wil not actually happen. For example, we can't document that 9.x update numbers must start with 90001 because there is no reason to do that now if we don't get to 8.10. And I also don't think we should switch *now* to 80601.

We could postpone this issue and dig it out again when we actually get there? Or have a follow-up?

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB

@xjm
Documenting this sounds like a good idea. What about a documentation like this

I think having test coverage now is still useful, otherwise we don't detect it, in case we introduce this problem due to some other changes ...

berdir’s picture

Status: Needs review » Needs work

I thought about just adding that. But if we do that, then we also need to document that if you *ever* do that, you will need to stick to 2 digits then for the minor version also for the future. And at least for core, once get to 8.10, we will want to switch every module to two minor digits for 9.x even if they didn't have any high update functions in 8.x.

dawehner’s picture

Good point.

You would need to do that within a given file, right? Could we validate that somehow and throw a warning in case someone has N and N-1 digit update functions?

berdir’s picture

Hm. Having 8901 and 81001 is perfectly fine. Just 81001 and then 9001 wouldn't make sense*. So we'd need to verify that the first digit is larger but it has fewer digits?

Not sure, you will find out quickly if your update function isn't being executed?

* this is an interesting example though. Lets say we go until 8.9 and then the next release is 9.0. That means we need to be aware that we can *not* ever add a 8.10 for whatever reason and expect to be able to add 81001 update functions. But even for that, there's a fairly simple workaround. We can just start at 8950 or so. After all, it is just a number, we'd just violate a bit our semantics. Afaik our current release schedule doesn't plan on having that situation and we could still decide that we will switch to 5 digits in 9.x even if we don't reach 8.10, just to be on the safe side?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

xjm’s picture

Status: Needs work » Closed (duplicate)
Issue tags: -Triaged D8 critical

We've ended up addressing this documentation in #3010334: Document how contrib hook_update_N() should be numbered now that modules can be compatible with multiple major branches and versioned semantically since semver for contrib, almost getting to 8.10, and core itself approaching major version 10 all mean things are more and more likely to switch to five digits. Closing as a duplicate of that issue.