### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

crash

### Expected behaviour

no crash

### Steps to reproduce

* Compile 79e8247ddb166f9b980f40249b7372a502402a4d
* Type `migratewallet`

### Relevant log output

```
wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
Aborted (core dumped)
```


### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

current master

### Operating system and version

Linux

### Machine specifications

_No response_
if (nZapSelectTxRet != DBErrorsLOAD_OK)
        return nZapSelectTxRet;
    MarkDirty();
    return DBErrorsLOAD_OK;
}
bool CWalSetAddressBookWithDB(WalBatch& batch, const CTxDestination& address, const stdstring& strName, const stdoptional<AddressPurpose>& new_purpose)
{
    bool fUpdated = false;
    bool is_mine;
    stdoptional<AddressPurpose> purpose;
    {
        LOCK(cs_wal);
        stdmap<CTxDestination, CAddressBookData>iterator mi = m_address_book.find(address);
        fUpdated = (mi != m_address_book.end() && !mi->second.IsChange());
        m_address_book[address].SetLabel(strName);
        is_mine = IsMine(address) != ISMINE_NO;
        if (new_purpose) { /* update 
            purpose = m_address_book[address].purpose = new_purpose;
        } else {
            purpose = m_address_book[address].purpose;
        }
    }
    // In very old wals, address purpose may not be recorded so we derive it from IsMine
    NotifyAddressBookChanged(address, strName, is_mine,
                             purpose.value_or(is_mine ? AddressPurposeRECEIVE  AddressPurposeSEND),
                             (fUpdated ? CT_UPDATED  CT_NEW));
    if (new_purpose && !batch.WritePurpose(EncodeDestination(address), PurposeToString(*new_purpose)))
        return false;
    return batch.WriteName(EncodeDestination(address), strName);
}