Deleting Records

Danger

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

Note

Please note that this is not a full command list, if you’re missing commands, feel free to ask over at the Community.

Removing 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) and delete the rest:

>> tickets_to_keep = [1, 2, 3]
>> Ticket.where.not(id: tickets_to_keep).destroy_all

Removing Users

Warning

  • Deletion via console is not recommended. Use Zammad’s data privacy UI feature to delete users and organizations.

  • Customers cannot be deleted while they have tickets remaining in the system. The examples below will delete all tickets associated with them as well.

  • The commands below remove data without requiring a confirmation.

Removing users is possible in 2 ways: A single user and in bulk.

>> User.find_by(email: '<email address>').destroy

Removing Organizations

Note

Removing 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 of the notes field:

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

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

     puts "  Deleting #{org.name}..."
     org.destroy
   end

Removing 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

Hint

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

Don’t forget to stop Zammad before trying to reset your instance!

Truncate the database:

$ rake zammad:db:truncate

Migrate the database:

$ rake db:migrate

Load the seed data:

$ rake db:seed

Clear the cache and reload the settings:

$ rake zammad:db:rebuild

Hint

You can also use the zammad:db:reset command to reset your instance. This task will truncate the database, run the migrations, seed the database, clear the cache and reload the settings. However, it will not ask for your confirmation between each step, so you should use it with caution.