diff --git a/db/migrate/20220318125144_issue4018_remove_old_translations.rb b/db/migrate/20220318125144_issue4018_remove_old_translations.rb new file mode 100644 index 000000000..ed0851dbe --- /dev/null +++ b/db/migrate/20220318125144_issue4018_remove_old_translations.rb @@ -0,0 +1,10 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +class Issue4018RemoveOldTranslations < ActiveRecord::Migration[6.0] + def change + # return if it's a new setup + return if !Setting.exists?(name: 'system_init_done') + + Translation.where(source: 'FORMAT_DATE', is_synchronized_from_codebase: false).find_each(&:destroy) + end +end diff --git a/spec/db/migrate/issue_4018_remove_old_translations_spec.rb b/spec/db/migrate/issue_4018_remove_old_translations_spec.rb new file mode 100644 index 000000000..b07f4c236 --- /dev/null +++ b/spec/db/migrate/issue_4018_remove_old_translations_spec.rb @@ -0,0 +1,14 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe Issue4018RemoveOldTranslations, type: :db_migration do + before do + create(:translation, source: 'FORMAT_DATE', target_initial: 'Datum', target: 'Datum', is_synchronized_from_codebase: false) + end + + it 'does remove old translations for source "FORMAT_DATE"' do + migrate + expect(Translation.where(locale: 'de-de', source: 'FORMAT_DATE').count).to eq(1) + end +end