Reset pk’s for postgresql after any importing of data with id’s.
This commit is contained in:
parent
550b963ad0
commit
9489dff71d
5 changed files with 37 additions and 9 deletions
|
@ -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(
|
||||
|
|
|
@ -146,6 +146,9 @@ returns
|
|||
}
|
||||
}
|
||||
|
||||
# reset primary key sequences
|
||||
DbHelper.import_post
|
||||
|
||||
# remove auto wizard file
|
||||
FileUtils.rm auto_wizard_file_location
|
||||
|
||||
|
|
31
lib/db_helper.rb
Normal file
31
lib/db_helper.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue