totten / civix

CiviCRM Extension Builder
http://civicrm.org/
Other
56 stars 56 forks source link

Database Upgraders - Continuing support for <5.37? #317

Closed totten closed 8 months ago

totten commented 9 months ago

(This is an off-shoot from discussion with @jaapjansma in https://lab.civicrm.org/extensions/civirules/-/merge_requests/221.)


Definition

The "Database Upgrader Class" (civix generate:upgrader) is a mechanism for managing schema changes on behalf of an extension. One defines a class similar to this (pseudocode):

class CRM_Myextension_Upgrader extends SomeBaseClass {
  public function install() {
    $this->doSomeInstallStuff();
  }

  public function upgrade_1000() {
    $this->doSomeUpgradeStuff();
  }
}

Mechanism (General)

This mechanism relies on two major pieces:

  1. Base Class: There's a base-class with common methods/behaviors. (These are behaviors like "check revision numbers", "execute a SQL template", or "add new SQL column").
  2. Event Wiring: You need to call the class whenever the extension is installed, uninstalled, upgraded, etc. (In other words, listen to "Lifecycle Hooks".)

The approach has evolved:

(Aside: Neither of these approaches use "mixins". The goal is similar -- reduce boilerplate. But the APIs+mechanics are different.)

Mechanism (Civix changes)

As of v22.12.1, civix made a full switch from heavy upgrade-classes (<=5.37) to light upgrade-classes (>=5.38). It warns before doing so, but it doesn't provide any alternatives.

Alternatives

Personally, if I needed to use current civix to make a database-upgrader for on an old CiviCRM, I would consider backporting https://github.com/civicrm/civicrm-core/pull/20091 + https://github.com/civicrm/civicrm-core/pull/20090 + https://github.com/civicrm/civicrm-core/pull/20116 (and possibly 1-2 bugfixes related to cache-management). The upshot is that the old Civi would run newer extensions. I like that git logs provide pointers on what to do. But obviously the cost-benefit calculus varies based on specific version#s, #deployments, patch-mgmt tooling, #extensions, etc.

Alternatively, if one really needs a more flexible generator... something generate DB-upgraders in either old or new style... then yes, I do think it's possible. After all, we do have working templates for both styles. But I think it sounds easier than it actually is.

I suppose... the smallest adaptation might be something like...

totten commented 8 months ago

I believe the issue became moot when CiviRules made a major-version branch. (A maintenance branch for <5.37 with older civix templates; another branch for >5.38 with newer civix templates.) If someone wants to purse, then... I guess comment+reopen...