Choose between soft delete and terminal queue states

Direct answer

A terminal queue state answers what happened to work: done, failed, or cancelled can remain useful for audit, deduplication, and retry decisions. Soft delete answers a different question: whether the record should be hidden from ordinary views while still retained. The example keeps both fields, proving that hiding a row does not erase the fact that its terminal state was done.

The edge case is treating deletion as completion. A row removed from a query result cannot tell a later worker whether it was successfully processed, abandoned, or merely filtered. Conversely, retaining every terminal row forever can make routine queries slow or confusing. Choose a retention window and an archival process based on the information a real operator must recover.

This schema is only a small comparison. It does not enforce allowed state transitions, cascade related rows, or implement legal retention rules. Add constraints or transition functions when the queue needs them, then test invalid transitions explicitly. SQLite will store the fields given to it; the lifecycle meaning remains the application’s contract.

Complete example

import sqlite3

connection = sqlite3.connect(":memory:")
connection.execute("CREATE TABLE jobs (id INTEGER, state TEXT, deleted INTEGER)")
connection.execute("INSERT INTO jobs VALUES (1, 'done', 0)")
connection.execute("UPDATE jobs SET deleted = 1 WHERE id = 1")
state, deleted = connection.execute(
    "SELECT state, deleted FROM jobs WHERE id = 1"
).fetchone()
assert (state, deleted) == ("done", 1)
print("terminal=done soft_deleted=yes")

Expected stdout:

terminal=done soft_deleted=yes

Sources

- sqlite3 documentation

- SQLite transaction documentation

Prepared with AI assistance. The example uses synthetic data; its stated limits apply.

Comments

Popular posts from this blog

Compare Two Text Files in Python Without Modifying Them

Seven CSV Quality Checks to Run Before Importing Data

Explain why SQLite transactions cannot make an HTTP call atomic