Add SCMTool ID to Repository model.

Review Request #12332 — Created June 3, 2022 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

As part of the effort towards creating a registry for SCMTools, we're
working towards deprecating the old Tool 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 called scmtool_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.

Diff Revision 1

This is not the most recent revision of the diff. The latest diff is revision 2. See what's changed.

orig
1
2

Commits

First Last Summary ID Author
Add SCMTool ID to Repository model.
As part of the effort towards creating a registry for SCMTools, we're working towards deprecating the old `Tool` 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 called `scmtool_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. Testing Done: Set up a bunch of different repositories and ran `manage.py upgrade`. Saw that the new field was populated correctly.
39cae00435f219b7a837002e16e5879121b34da6 David Trowbridge
reviewboard/manage.py
reviewboard/upgrade.py
reviewboard/scmtools/admin.py
reviewboard/scmtools/models.py
reviewboard/scmtools/evolutions/__init__.py
reviewboard/scmtools/evolutions/repository_scmtool_id.py
Loading...