Skip to content

free legacy soft-deleted workflow names#4844

Closed
elias-ba wants to merge 2 commits into
sandbox-merge-followupsfrom
backfill-deleted-workflow-names
Closed

free legacy soft-deleted workflow names#4844
elias-ba wants to merge 2 commits into
sandbox-merge-followupsfrom
backfill-deleted-workflow-names

Conversation

@elias-ba

@elias-ba elias-ba commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

A one-off release task to free the names of workflows soft-deleted before merges renamed on delete. They still hold their original name, which the uniqueness rule uses to block a later merge from recreating it (~900 such workflows in prod). #4842 stops new ones forming; this clears the existing ones.

Lightning.Release.backfill_deleted_workflow_names/1 (via bin/backfill_deleted_workflow_names) renames each to name_del, reusing the app's existing logic. Idempotent, with a dry_run: true option.

Validation steps

In iex -S mix, seed a few soft-deleted workflows including a collision:

alias Lightning.Repo
alias Lightning.Projects.Project
alias Lightning.Workflows.Workflow

now = DateTime.utc_now() |> DateTime.truncate(:second)
project = Repo.insert!(%Project{name: "backfill-demo"})

# never-renamed soft-deletes
Repo.insert!(%Workflow{project_id: project.id, name: "Patient Sync", deleted_at: now})
Repo.insert!(%Workflow{project_id: project.id, name: "Report", deleted_at: now})
# collision: "Report_del" is already taken
Repo.insert!(%Workflow{project_id: project.id, name: "Report_del", deleted_at: now})
# control: a live workflow, should stay untouched
Repo.insert!(%Workflow{project_id: project.id, name: "Live One"})

Then:

  1. Lightning.Release.backfill_deleted_workflow_names(dry_run: true) reports the count and writes nothing.
  2. Lightning.Release.backfill_deleted_workflow_names() frees the names: Patient Sync becomes Patient Sync_del, Report becomes Report_del1 (since Report_del is taken), Live One is untouched.
  3. Re-running returns {:ok, 0}.

Additional notes for the reviewer

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review
    with Claude Code)
  • I have implemented and tested all related authorization policies.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

Workflows soft-deleted before merges renamed on delete still hold their
original (name, project_id), which the uniqueness rule uses to block a later
merge from recreating that name. Add a release task,
Lightning.Release.backfill_deleted_workflow_names/1 with a bin wrapper, that
renames them to name_del the same way the app now does, reusing
resolve_name_for_pending_deletion so freed names match. Idempotent, with a
dry_run option. Removed in the follow-up cleanup PR once the cutover has run.
@github-project-automation github-project-automation Bot moved this to New Issues in Core Jun 9, 2026
@elias-ba elias-ba changed the title Free legacy soft-deleted workflow names (post-#4842 cutover) Free legacy soft-deleted workflow names Jun 9, 2026
@elias-ba elias-ba changed the title Free legacy soft-deleted workflow names free legacy soft-deleted workflow names Jun 9, 2026
@elias-ba elias-ba requested a review from doc-han June 9, 2026 22:39
@elias-ba elias-ba marked this pull request as ready for review June 9, 2026 22:44
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.4%. Comparing base (bc12040) to head (a02428b).

Additional details and impacted files
@@                   Coverage Diff                   @@
##           sandbox-merge-followups   #4844   +/-   ##
=======================================================
  Coverage                     90.4%   90.4%           
=======================================================
  Files                          444     444           
  Lines                        22632   22632           
=======================================================
  Hits                         20453   20453           
  Misses                        2179    2179           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Security Review ✅

  • S0 (project scoping): N/A — the only data-touching change is a release-time operator task (lib/lightning/release.ex:80) invoked via bin/backfill_deleted_workflow_names; it intentionally scans all soft-deleted workflows, and the collision lookup in Workflows.resolve_name_for_pending_deletion/1 already filters by project_id (lib/lightning/workflows.ex:779).
  • S1 (authorization): N/A — no new LiveView events, controller actions, or channel handlers; the new entrypoint is a shell wrapper requiring operator/release-image access, and the sandbox log change at lib/lightning/projects/sandboxes.ex:214-235 does not alter any auth gate.
  • S2 (audit trail): PASS — the rename is a corrective backfill on rows whose original soft-delete was already audited via Audit.marked_for_deletion in Workflows.mark_for_deletion/3 (lib/lightning/workflows.ex:725), so no new state-transition audit is required for the operator-time name freeing.

@elias-ba

Copy link
Copy Markdown
Contributor Author

Closing this. The team's conclusion is that the real fix is the missing workflow purge lifecycle (#4163), not a one-off backfill. Renaming the existing rows just patches one symptom (merge name collisions); #4163 will purge soft-deleted workflows properly once their history has aged out under the project's retention, and can weigh the partial-index option that removes the rename approach altogether. Folding the intent into #4163 rather than shipping the bandaid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants