Data Retention Policies
Define data retention periods and automated expiry actions (Delete or Anonymize) for GDPR Article 5(1)(e) compliance.
Data Retention Policies define how long specific categories of data must be kept and what happens when the retention period expires. SCRIPE enforces these policies automatically via background jobs, removing the manual overhead of managing data lifecycles.
Retention Policy Evaluation Flow
The automated retention engine scans database tables periodically, evaluating record age against configured retention thresholds.
Expiry Actions
When a retention period expires, SCRIPE applies one of two actions:
| Action Type | Description | Primary Use Cases |
|---|---|---|
| Hard Delete | Permanently purges matching records and dependencies from physical storage. | Statutory mandatory deletion, temporary cache files, transient sessions. |
| Soft Delete | Marks records as inactive and excluded from operational queries while preserving history. | Standard business entities requiring legal hold or graceful user deactivation. |
| Anonymize | Replaces PII with pseudonymized tokens while retaining aggregated reporting metrics. | Financial transactions, analytics events, order histories, billing ledgers. |
Retention Policy Service Registration
Registering custom retention evaluators and scheduling Hangfire recurring execution jobs.
public class RetentionEnforcementJob : IAutoRegisteredJob
{
public string JobId => "compliance-retention-enforcement";
public string CronExpression => "0 2 * * *"; // Run daily at 2 AM
public async Task ExecuteAsync(CancellationToken ct)
{
var policies = await _dbContext.RetentionPolicies
.Where(p => p.IsActive)
.ToListAsync(ct);
foreach (var policy in policies)
{
var execution = new RetentionExecution { PolicyId = policy.Id };
try
{
var affectedCount = await _retentionExecutor.ExecutePolicyAsync(policy, ct);
execution.Status = ExecutionStatus.Completed;
execution.RecordsAffected = affectedCount;
}
catch (Exception ex)
{
execution.Status = ExecutionStatus.Failed;
execution.ErrorMessage = ex.Message;
}
await _dbContext.RetentionExecutions.AddAsync(execution, ct);
}
await _dbContext.SaveChangesAsync(ct);
}
}Retention Data Model
Configurable retention rules specifying target entities, retention periods in days, and disposal actions (Anonymize or Purge).
| Field Name | Data Type | Define data retention periods and automated expiry actions (Delete or Anonymize) for GDPR Article 5(1)(e) compliance. |
|---|---|---|
| TenantId | Guid | Tenant workspace owning this retention policy rule. |
| RegulationProfileId | Guid | Jurisdiction regulation profile governing this retention policy. |
| Name | String | Descriptive name of the retention policy. |
| Description | String? | Detailed business justification and scope of the retention policy. |
| Category | Enum | Target data category governed by this retention schedule. |
| RetentionDays | Int32 | Default retention period duration in days before action is executed. |
| MinRetentionDays | Int32 | Minimum statutory holding period before deletion is legally permissible. |
| MaxRetentionDays | Int32 | Maximum allowable storage duration under GDPR storage limitation principle. |
| ExpiryAction | String | Automated action executed upon expiry (Delete, SoftDelete, or Anonymize). |
| NextEvaluationAt | DateTime | Timestamp scheduled for the next automated policy evaluation run. |
| IsActive | Boolean | Whether the retention policy is active and enforced by background workers. |
API Endpoints
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/v1/compliance/retention | List all configured retention policies and schedules for the tenant. | 🔒 Required |
| PUT | /api/v1/compliance/retention/{id} | Update retention threshold days, expiry actions, or active status. | 🔒 Required |
| GET | /api/v1/compliance/retention/executions | Retrieve historical retention execution logs and purged record counts. | 🔒 Required |