Skip to content

Instantly share code, notes, and snippets.

@unlight
Created January 18, 2021 18:10
Show Gist options
  • Save unlight/81a284a4f293c8f8e97919ff787edfd8 to your computer and use it in GitHub Desktop.
Save unlight/81a284a4f293c8f8e97919ff787edfd8 to your computer and use it in GitHub Desktop.
Soft delete records SQL

How to

Soft delete records SQL

  • Use table RecycleBin with columns id, model, data
  • Move deleted records to RecycleBin
  • Serialize all rows to json and save to data
model Customer {
  customerId String @id @default(cuid())
  name       String
}

model RecycleBin {
  id    String
  model String
  data  Json
  @@id([id, model])
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment