diff --git a/db/seeds.rb b/db/seeds.rb index 5762b971d..849fabaae 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5447,11 +5447,7 @@ Karma::Activity.create_or_update( ) # reset primary key sequences -if ActiveRecord::Base.connection_config[:adapter] == 'postgresql' - ActiveRecord::Base.connection.tables.each do |t| - ActiveRecord::Base.connection.reset_pk_sequence!(t) - end -end +DbHelper.import_post # install locales and translations Locale.create_if_not_exists( diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index 509409a04..9e71fbeed 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -146,6 +146,9 @@ returns } } + # reset primary key sequences + DbHelper.import_post + # remove auto wizard file FileUtils.rm auto_wizard_file_location diff --git a/lib/db_helper.rb b/lib/db_helper.rb new file mode 100644 index 000000000..27b61f699 --- /dev/null +++ b/lib/db_helper.rb @@ -0,0 +1,31 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ + +class DbHelper + +=begin + +execute post database statements after import (e. g. reset primary key sequences for postgresql) + + DbHelper.import_post + +or only for certan tables + + DbHelper.import_post(table_name) + +=end + + def self.import_post(table = nil) + return if ActiveRecord::Base.connection_config[:adapter] != 'postgresql' + + tables = if table + [table] + else + ActiveRecord::Base.connection.tables + end + + tables.each do |t| + ActiveRecord::Base.connection.reset_pk_sequence!(t) + end + end + +end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index eb5a6971e..0fb26b19e 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -1526,8 +1526,7 @@ module Import::OTRS # reset primary key sequences def self._reset_pk(table) - return if ActiveRecord::Base.connection_config[:adapter] != 'postgresql' - ActiveRecord::Base.connection.reset_pk_sequence!(table) + DbHelper.import_post(table) end # create customers for article diff --git a/lib/import/zendesk.rb b/lib/import/zendesk.rb index 4e9bc9ab6..838525e20 100644 --- a/lib/import/zendesk.rb +++ b/lib/import/zendesk.rb @@ -998,8 +998,7 @@ module Import::Zendesk # reset primary key sequences def self._reset_pk(table) - return if ActiveRecord::Base.connection_config[:adapter] != 'postgresql' - ActiveRecord::Base.connection.reset_pk_sequence!(table) + DbHelper.import_post(table) end def get_custom_fields(custom_fields)