Files
sure/app/models/demo/data_cleaner.rb
LPW ff55b977d4 Add sso_audit_logs association and clear logs in demo data cleaner (#638)
- Added `has_many :sso_audit_logs` association to `User` model with `dependent: :nullify`.
- Updated `Demo::DataCleaner` to clear SSO audit logs before destroying related data.

Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
2026-01-13 17:44:51 +01:00

32 lines
806 B
Ruby

# SAFETY: Only operates in development/test environments to prevent data loss
class Demo::DataCleaner
SAFE_ENVIRONMENTS = %w[development test]
def initialize
ensure_safe_environment!
end
# Main entry point for destroying all demo data
def destroy_everything!
# Clear SSO audit logs first (they reference users)
SsoAuditLog.destroy_all
Family.destroy_all
Setting.destroy_all
InviteCode.destroy_all
ExchangeRate.destroy_all
Security.destroy_all
Security::Price.destroy_all
puts "Data cleared"
end
private
def ensure_safe_environment!
unless SAFE_ENVIRONMENTS.include?(Rails.env)
raise SecurityError, "Demo::DataCleaner can only be used in #{SAFE_ENVIRONMENTS.join(', ')} environments. Current: #{Rails.env}"
end
end
end