CodamAIDocs
Topicdone

Deleting file models

When a file model is deleted, the record, the file content and all retained versions disappear. The history of the record remains, the content does not.

Variants
deleted directlydeleted along through the DELETE flag (1:1, 1:n)removed from the parent through PUT/PATCHshared file (n:1, n:m) → staysall versions gone

What this is about

A file model has two parts: the record in the database (name, size, fileId and your own fields) and the content in the file storage. For audited file models, the storage also holds the old versions of every upload. See File versions.

When the record is deleted, CDMS deletes the content along with it, and that means all versions. A file model whose record is gone has no readable content left. This matters for personal data: a deletion is only a deletion once the bytes are gone too.

Record and content

  1. 1
    Client→CDMS
    sends DELETE /fileasset/delete/f1…
  2. 2
    CDMS
    checks visibility and the delete role of the file model
  3. 3
    CDMS→File storage
    notes that the content is to be removed: the current file and all retained versions
    It is noted during the delete flow as soon as CDMS reaches the record. It is removed only after the database commit.
  4. 4
    Hook
    DELETE hooks run
  5. 5
    CDMS→Database
    removes the record and commits
  6. 6
    CDMS→File storage
    removes the content including versions
    Result: 200 without body. GET /fileasset/f1…/file returns 404 afterwards.

In the file storage it looks like this, for an audited file model with three uploads:

File in storagebeforeafter
<fileId> (current content)“version three”deleted
<fileId> + version identifier“version two”deleted
<fileId> + version identifier“version one”deleted

Which files go along

A file can hang on another object, such as the logo of a company or the attachments of a dossier. Whether it goes along when that object is deleted is, as always, decided by the DELETE flag. See Dependent objects (cascades).

The parent is deleted. What happens to the file?
RelationExampleFlag DELETEFile
1:1Company.logoyesrecord and content deleted
1:nDossier.attachmentsyesevery attachment deleted, with content
n:1Dossier.template, one template for many dossiersnostays with its content, even if no dossier points to it anymore
n:m through a join modelDossier.assets → Dossier2Asset.assetyes on the join, no on the filethe connections go, the file stays

So a shared file stays, even when the last object pointing to it is deleted. CDMS does not clean it up by itself. If you no longer need it, delete it directly.

Removed through PUT or PATCH

If a dependent attachment drops out of its list through PUT or PATCH, it is deleted, likewise with its content and versions. See Deleting by changing.

Replacing a file is something else: a new upload to the same record deletes nothing; for audited models the old content becomes a version. See Replacing and renaming.

What remains of a deleted file

After deleting an audited file model
Remains
  • the history of the record: name, size, who uploaded and deleted it and when
Is gone
  • the record
  • the current content
  • all versions
  • every way to download an old content

So the history shows that the file existed and what it was called, but no longer what was in it. See What remains after a delete.

Pitfalls

What comes next

Sources in the code and the knowledge base
  • CDMS/cdms-system-layer – AbstractLayer.recursiveDelete (FileInterface → fileStorage().stageDeletion, followTransaction)
  • CDMS/cdms-localfs-storage – LocalFSFileController.deleteFile (listSideFiles: versions and leftover staged files)
  • CDMS/cdms-integrationtest – AbstractRecursiveFileDeleteTest (1:1, 1:n, n:1, n:m), AbstractFileRollbackTest.deleteRemovesEveryUploadOfTheRecord, aRefusedDeleteKeepsTheContentAndItsHistory
  • documentation/05-api-guide/06-schreiben.md, 20-api/04-schreibsemantik.md, 30-daten-und-persistenz/05-dateien-und-storage.md
Search