initialize
will normally initialize all state, and will be used during testing and so on. In an upgrade, you usually only want to initialize a subset of the state (the new state).
So you probably want to have a separate function initializeV2
that only initializes the new state that's introduced in an upgrade.
This is the reason we released "reinitializers" in OpenZeppelin Contracts 4.6. You can define something like
function initializeV2() reinitializer(2) {
// initialize new variables
}
This is like an initializer function, it can only be invoked once, but note that if you had used initializer
as the modifier for this function you would never be able to call it: the contract is already initialized! reinitializer(2)
defines a new "version" (2 in this case) that you can initialize.