Deleting Records


☠️ The commands listed here cause irrecoverable data loss! Only proceed if you know what you’re doing and you have a backup!


The list of commands below is not exhaustive. If you can’t find what you’re looking for here, you are encouraged to ask the community.

Deleting Tickets (and their articles)

# Delete a ticket (specified by database ID)
>> Ticket.find(4).destroy

# Delete all tickets
>> Ticket.destroy_all

# Keep some tickets (specified by database ID); delete the rest
>> tickets_to_keep = [1, 2, 3]
>> Ticket.where.not(id: tickets_to_keep).destroy_all

Deleting Customers


Customers may not be deleted while they have tickets remaining in the system.

As such, the examples below will delete not only the specified customers, but all tickets associated with them, as well.

Step 1: Select customers by email address
>> customer_emails = %w[]

>> customers = User.joins(roles: :permissions).where(email: customer_emails, roles: { active: true }, permissions: { name: 'ticket.customer', active: true }).where.not(id: 1)
Step 2: Preview affected users & tickets
>> puts { |user| <<~PREVIEW }.join("\n")
     Customer #{user.fullname}/#{}/#{} has #{Ticket.where(customer_id:} tickets #{Ticket.where(customer_id:}
Step 3: Proceed with deletion
>> customers.find_each do |user|
     puts %{Preparing deletion of customer "#{user.fullname}" (and #{Ticket.where(customer_id:} associated tickets)}

     Ticket.where(customer: user).find_each do |ticket|
       puts "  Deleting ticket ##{ticket.number}..."

     puts "  Removing references for user with email #{}..."
     ActivityStream.where(created_by_id: 1)
     History.where(created_by_id: 1)
     Ticket::Article.where(created_by_id: 1)
     Ticket::Article.where(updated_by_id: 1)
     Store.where(created_by_id: 1)
     StatsStore.where(created_by_id: 1)
     Tag.where(created_by_id: 1)

     puts "  Deleting #{user.fullname}..."

Deleting Organizations


Deleting an organization does not delete associated customers.

Step 1: Select organizations
# by "active" status
>> organizations = Organization.where(active: false)

# by name
>> organizations = Organization.where(name: 'Acme')

# by partial match on notes
>> organizations = Organization.where('note LIKE ?', '%foo%')
Step 2: Preview affected organizations
>> puts { |org| "ORGANIZATION #{}" }.join("\n")
Step 3: Proceed with deletion
>> organizations.each do |org|
     puts %{Preparing deletion of organization "#{}"...}

     org.members.each do |member|
        puts "  Removing #{member.fullname} from organization..."
        member.update!(organization_id: nil)

     puts "  Deleting #{}..."

Deleting System Records

# Remove all online notifications
>> OnlineNotification.destroy_all

# Remove all entries from the Activity Stream (dashboard)
>> ActivityStream.destroy_all

# Remove entries for all recently viewed objects (tickets, users, organizations)
>> RecentView.destroy_all

# Remove all history information from tickets, users and organizations (dangerous!)
>> History.destroy_all

Reset Zammad installation


Below commands are incomplete intentionally, error outputs will hint you through! The following operations will cause data loss and for development / testing only.

Don’t forget to stop Zammad before trying to drop the database!

$ rake db:drop
$ rake db:create
$ rake db:migrate
$ rake db:seed