Standartize numbering of hook_update_N following the module semantic versioning

Created on 6 November 2024, about 1 month ago

Problem/Motivation

From Drupal 9.x many modules started to use Semantic Versioning instead of matching the Drupal Core version number, so instead of something like 9.x-2.5 - we have something like 2.5.0.

But the numbering of the hook_update_N functions remains the same, as with the previous approach, like

function my_module_update_8001()
function my_module_update_9405()
function my_module_update_10324()

etc.

We already have an issue πŸ“Œ Document how contrib hook_update_N() should be numbered now that modules can be compatible with multiple major branches and versioned semantically Fixed about this topic, that is even already closed, but in the results I see no improvements in recommendations on how to number the hook_update_N functions, related to the semantic version number of the module.

So, seems we need to raise this issue again and describe the exact recommended approach of calculating the hook_update_N number the same way for most of the modules.

Steps to reproduce

1. Start thinking about what number to choose for hook_update_N of the new release of a contrib module, that is compatible with Drupal 9.x, 10.x, 11.x together.

2. Get confused about this.

Proposed resolution

Let's define this approach to calculate the number for the hook_update_N:

Here is a template from the Semantic Version string, using the contraction letters from the version: MMmmPPddd, where:

  • M - major version number, always 2 characters with leading zeros.
  • m - minor version number, always 2 characters with leading zeros.
  • P - patch version number, always 2 characters with leading zeros.
  • d - delta from the last released patch version, always 2 characters with leading zeros, starting with 01.

Start to use two numbers for each version number, that should be enough for most cases. If at some time your module exceeds the limit, you can just switch to three numbers in the version number for this release and all the next releases.

Examples:

  • version 0.1.0 - 1st hook_update: 00010001 (parts: 00_01_00_01)
  • version 0.1.0 - 2nd hook_update: 00010002
  • version 1.4.6 - 4th hook_update: 01040604
  • version 12.34.17 - 1st hook_update: 12341701
  • version 12.34.18-dev - 5th hook_update on the 12.34.18 release - 12341805
  • version 12.34.18-alpha7 - 11th hook_update on the 12.34.18 release - 12341811
  • version 12.34.18-beta1 - 16th hook_update on the 12.34.18 release - 12341816
  • version 12.34.18 - 25th hook_update after the 12.34.17 release - 12341825

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

documentation

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @murz
  • Which documentation page or file needs to change?

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Which documentation page or file needs to change?

    I think this page: https://www.drupal.org/docs/drupal-apis/update-api/introduction-to-the-u... β†’

    And the inline documentation here: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    contrib doesn't have 0.x major versions, it starts with 1.x AFAIK, so numbers starting with 0 wouldn't exist. They also wouldn't work, the update number is a single integer, and right now the lowest number that you can pick is 8001 (for now, it references an issue to remove that requirement). There is AFAIK an issue to change that, but anything else is entirely up to you.

    I do agree that the documentation can be improved, the part about core compatibility can be dropped, it's only about your own module.

    I think the most sensible thing is then to just start with 10000 or 1 major 00 minor and 00 for the update number. I'd not put in patch for contrib modules because that will just require you to update it whenever there's a new patch version.

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Also found an issue that we can't use numbers with leading zeros because it leads to not finding the hook_update function, so if we use hook_update_08001 - it will show the error:

      In update.inc line 357:
        Function commercetools_update_8001() does not exist
    

    So, updated the description again.

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Here is a suggestion for numbering pre-stable release numbers like 0.1.0:

    Let's stick to 8001+ for that case, because .80 is used in some software version numbering as alpha, .90 as beta (eg in KDE releases like 5.80.0 - 6.0-alpha1, 5.90.0 - 6.0.0-beta1, 5.95.0 - 6.0.0-beta2, 6.0.0 - 6.0.0 release).

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Updated the issue body with the new changes, please review.

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    that is even already closed, but in the results I see no improvements in recommendations on how to number the hook_update_N functions, related to the semantic version number of the module.

    The linked API document and commit did add changes to describe versioning involving contrib modules that utilize semver.

    The linked issue and pages say that the numbering is
    CcMmII
    Cc = 1-2 digits for minimum version of core supported (this also guarantees our update hooks never have a leading 0 for 0.y.z branches)
    Mm - 1-2 digits for module major version
    II = 2 digit incremental.

    Start thinking about what number to choose for hook_update_N of the new release of a contrib module, that is compatible with Drupal 9.x, 10.x, 11.x together.

     If your module is compatible with multiple major versions (e.g., it has a core_version_requirement of '^8.8 || ^9'), use the lowest major core branch it is compatible with (8 in this example).
    

    is it this is possibly a support request for misunderstanding of what the current 'suggested' format is?

    Is core useful as part of the value? Maybe not, although it does add that nice protection for 0.x branches and allow modules to reset their counters every time the module drops support for a version of core.

    Under the existing standard do we need to consider starting any counter at 110000 minimally for 0.x branches since these may be in the wild already?

    I would actually suggest a minimum of 20000 if that is done in case πŸ“Œ Decide what to do with Drupal::CORE_MINIMUM_SCHEMA_VERSION and surrounding logic Active decides that we will bump the minimum version to 120000 in the 12.x release (unlikely, however we never know what will happen with this value in the future until it is actually removed) as that would at least hold us for up to 16 years.

    Biggest question to ask: How many incremental do you need each minor/major for each minimum core supported by a module? Do you really need 99 update hooks per MINOR release or is 99 per major sufficient in which case the existing numbering scheme already covers this. I have heard of some long running modules in the past (before hook_post_update()) having issues, is that still a problem today?

    Second question is if you have a long running issue, do you really want to edit the update hook number in a MR because the module released a new minor release while the issue was in-progress?

    Tagging as Needs IS update, recommend removing the references to no standard and adjust to reflect why the existing recommended format should be changed.

Production build 0.71.5 2024