Open link in a new tab

Content

Expand project menu

Recommended way to "reset" database

Hi everyone!

I'm building a procedure to migrate our Wrike data to OpenProject. I was wondering, since I'm creating a lot of test projects and work packages, is there a recommended way to "reset" the OP database that removes all projects, all WPs and all attachments, while leaving the other settings alone (for example the users)?

I have a dump of the DB "initial" state, but I guess that, if I just restore it, the attachments will be left on disk.

EDIT:

Can I use the Rails console? Is this "good" practice? Or at least acceptable? 😁 

while WorkPackage.exists?
  begin
    WorkPackage.destroy_all
  rescue ActiveRecord::StaleObjectError
  end
end

while Project.exists?
  begin
    Project.destroy_all
  rescue ActiveRecord::StaleObjectError
  end
end

ActiveRecord::Base.connection.reset_pk_sequence!('work_packages')
ActiveRecord::Base.connection.reset_pk_sequence!('projects')

Thanks for your help!

Message actions

Hi there, it might work but I still wouldn't trust it. At the very least you would also have to consider the paper trail audits table which will now include delete audits for work packages which might be a bit confusing if new work packages with the same ID are created. Of course you could purge that too. But I'm not sure which other pitfalls there are.

I think the approach with the initial state database dump is the best. But yes, you are correct, that this will leave dangling attachments.
But if your initial state has no or a known set of attachments, it would be fairly easy to just delete all other attachments (say with an ID greater than N where N is the number of attachments in your initial state) in the attachments folder (e.g. /var/db/openproject/files depending on your installation method).

Message actions

I see, thanks for your help!