Add SCMTool ID to Repository model.
Review Request #12332 — Created June 3, 2022 and submitted — Latest diff uploaded
As part of the effort towards creating a registry for SCMTools, we're
working towards deprecating the oldTool
model, which was what we had
initially created to support multiple SCM types. This model was
initially populated via a database fixture, and over the years we've
moved to entry points, and (soon) to a registry for storing all of the
available tools.If
Tool
is going away over time, we need a new way for Repository to
keep track of what SCMTool it's supposed to use. This change adds a new
field calledscmtool_id
, which will be the ID that can be looked up in
the registry. Populating this field is a little complex because the
existing Tool object only stores the SCMTool class name, not the ID. We
therefore can't initialize the field from an evolution, even using
custom SQL. The solution we've settled on is to wrap the upgrade process
with something that will store a mapping of the existing ID relations,
run any database evolutions, and then apply the mapping to populate the
field.This should allow us to move that information from the Tool model (and
associated SCMTool class) into the Repository model during the upgrade,
even in the case where the evolutions being run delete the Tool model
entirely. For now the code that builds that stored info uses the Tool
model, but there's a note about how we'll need to update that to use
hand-written SQL queries when the model instance gets deleted in the
future.
Set up a bunch of different repositories and ran
manage.py upgrade
.
Saw that the new field was populated correctly.