From 2573723269f1b2d06e86325530a7fa70109d61cf Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Thu, 19 Aug 2021 16:42:36 +0200 Subject: [PATCH] Fixes #3702 - One of DB migrations timestamp breaks migrations queue --- .../cop/zammad/correct_migration_timestamp.rb | 35 +++++++++++++++++++ .rubocop/rubocop_zammad.rb | 1 + ...001_setting_add_internal_article_check.rb} | 6 ++++ 3 files changed, 42 insertions(+) create mode 100644 .rubocop/cop/zammad/correct_migration_timestamp.rb rename db/migrate/{202104070000001_setting_add_internal_article_check.rb => 20210407000001_setting_add_internal_article_check.rb} (70%) diff --git a/.rubocop/cop/zammad/correct_migration_timestamp.rb b/.rubocop/cop/zammad/correct_migration_timestamp.rb new file mode 100644 index 000000000..9b90c60ac --- /dev/null +++ b/.rubocop/cop/zammad/correct_migration_timestamp.rb @@ -0,0 +1,35 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +module RuboCop + module Cop + module Zammad + # This cop checks if migration file name begins with a valid timestamp + # https://github.com/zammad/zammad/issues/3702 + class CorrectMigrationTimestamp < Base + MSG = 'Migration filename must begin with a valid timestamp'.freeze + + def on_new_investigation + file_path = processed_source.file_path + + return if !migration?(file_path) + return if config.file_to_exclude?(file_path) || config.allowed_camel_case_file?(file_path) + return if filename_good?(file_path) + + add_global_offense(MSG) + end + + private + + def migration?(file_path) + match_path? %r{(?