Rename deletion_scheduled state to soft_deleted in Organizations

What does this MR do and why?

Renames the organization-specific state machine terminology from deletion_scheduled to soft_deleted, aligning with the organization lifecycle architecture design document.

Previously, organizations went through multiple deletion states: they could be "scheduled for deletion," then moved to "deletion in progress," and could be rescheduled or cancelled at various points. This created a complex workflow with multiple intermediate states and error handling.

The new approach simplifies this to just two main actions: "soft delete" (which marks an organization as deleted but keeps the data) and "restore" (which undoes the soft deletion). Organizations can also be "hard deleted" which permanently removes them.

Key changes include:

  • Renaming the database column from deletion_scheduled_at to soft_deleted_at to better reflect its purpose
  • Updating the state machine to use soft_deleted instead of deletion_scheduled
  • Simplifying the service class from MarkForDeletionService to SoftDeletionService
  • Removing complex rescheduling and cancellation logic in favor of simple restore functionality
  • Updating audit logs and error messages to reflect the new terminology

This makes the deletion process more straightforward for users and easier to maintain for developers, while still preserving the ability to recover accidentally deleted organizations.

References

Screenshots or screen recordings

N/A — backend-only change.

How to set up and validate locally

  1. Run the migrations: bundle exec rails db:migrate
  2. In rails console, verify the new state machine:
    org = Organizations::Organization.find(2) # any non-default org
    org.soft_delete!(transition_user: User.first)
    org.soft_deleted? # => true
    org.restore!
    org.active? # => true
  3. Run the specs:
    bundle exec rspec spec/models/concerns/organizations/stateful_spec.rb
    bundle exec rspec spec/services/organizations/soft_deletion_service_spec.rb

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Rémy Coutable

Merge request reports

Loading