Skip to content

Do not expire the PreviousChangesetSpec of a changeset

Created by: mrnugget

We expire CampaignSpecs and ChangesetSpecs in repo-updater:

https://github.com/sourcegraph/sourcegraph/blob/402b61a52ba6a36480eff5e827e963c2482ea7f0/enterprise/cmd/repo-updater/main.go#L63-L68

When do we expire?

  • CampaignSpecs are expired when they're not attached to a Campaign anymore.
  • ChangesetSpecs are expired when they're not attached to a CampaignSpec.

But since we extended ApplyCampaign we now have a CurrentSpecID and a PreviousSpecID on Changesets and set those:

https://github.com/sourcegraph/sourcegraph/blob/402b61a52ba6a36480eff5e827e963c2482ea7f0/enterprise/internal/campaigns/service.go#L581-L583

That means ApplyCampaign can leave us in a state where a Changeset has a PreviousSpecID that points to a ChangesetSpec that is attached to a CampaignSpec that's not attached to a campaign.

What we need to do:

  • Continue to expire campaignSpec that are not attached to campaigns anymore.
  • But don't clean up the ChangesetSpecs if they're attached to a Changeset, either as a CurrentSpecID or a PreviousSpecID.

For that we need to find out whether the deletion of a campaign_spec also deletes the associated changeset_specs. if that's the case, we need to stop.

And then, in DeleteExpiredChangesetSpecs, we need to not delete ChangesetSpecs that are attached to a changeset.