db_helper.rb 662 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class DbHelper
  3. =begin
  4. execute post database statements after import (e. g. reset primary key sequences for postgresql)
  5. DbHelper.import_post
  6. or only for certain tables
  7. DbHelper.import_post(table_name)
  8. =end
  9. def self.import_post(table = nil)
  10. return if ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] != 'postgresql'
  11. tables = if table
  12. [table]
  13. else
  14. ActiveRecord::Base.connection.tables
  15. end
  16. tables.each do |t|
  17. ActiveRecord::Base.connection.reset_pk_sequence!(t)
  18. end
  19. end
  20. end