Skip to main content
Warning This document has not been updated for a while now. It may be out of date.
Last updated: 15 Apr 2021

publishing-api: Deleting Documents, Editions and Links

To delete content from the Publishing API you will need to create a data migration.

If you need to delete all traces of a document from the system:

require_relative "helpers/delete_content"

class RemoveYourDocument < ActiveRecord::Migration
  # Remove /some/base-path
  def up
    Helpers::DeleteContent.destroy_documents_with_links("some-content-id")
  end
end

If you need to delete a single edition:

require_relative "helpers/delete_content"

class RemoveYourEdition < ActiveRecord::Migration
  def up
    editions = Edition.where(id: 123)

    Helpers::DeleteContent.destroy_supporting_objects(editions)

    editions.destroy_all
  end
end

If you need to delete just the links for a document:

require_relative "helpers/delete_content"

class RemoveLinks < ActiveRecord::Migration
  # Remove /some/base-path
  def up
    Helpers::DeleteContent.destroy_links("some-content-id")
  end
end