Commit 29280bee authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'fix_require_migration_helper' into 'master'

Do not check EE migration folders on FOSS for `require_migration!`

See merge request gitlab-org/gitlab!45886
parents 7b884854 48348daf
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190924152703_migrate_issue_trackers_data.rb')
require_migration!('migrate_issue_trackers_data')
RSpec.describe MigrateIssueTrackersData do
let(:services) { table(:services) }
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191015154408_drop_merge_requests_require_code_owner_approval_from_projects.rb')
require_migration!('drop_merge_requests_require_code_owner_approval_from_projects')
RSpec.describe DropMergeRequestsRequireCodeOwnerApprovalFromProjects do
let(:projects_table) { table(:projects) }
......
......@@ -3,23 +3,42 @@
require 'find'
class RequireMigration
MIGRATION_FOLDERS = %w(db/migrate db/post_migrate ee/db/geo/migrate ee/db/geo/post_migrate).freeze
class AutoLoadError < RuntimeError
MESSAGE = "Can not find any migration file for `%{file_name}`!\n" \
"You can try to provide the migration file name manually."
def initialize(file_name)
message = format(MESSAGE, file_name: file_name)
super(message)
end
end
FOSS_MIGRATION_FOLDERS = %w[db/migrate db/post_migrate].freeze
ALL_MIGRATION_FOLDERS = (FOSS_MIGRATION_FOLDERS + %w[ee/db/geo/migrate ee/db/geo/post_migrate]).freeze
SPEC_FILE_PATTERN = /.+\/(?<file_name>.+)_spec\.rb/.freeze
class << self
def require_migration!(file_name)
file_paths = search_migration_file(file_name)
raise AutoLoadError.new(file_name) unless file_paths.first
require file_paths.first
end
def search_migration_file(file_name)
MIGRATION_FOLDERS.flat_map do |path|
migration_folders.flat_map do |path|
migration_path = Rails.root.join(path).to_s
Find.find(migration_path).grep(/\d+_#{file_name}\.rb/)
end
end
private
def migration_folders
Gitlab.ee? ? ALL_MIGRATION_FOLDERS : FOSS_MIGRATION_FOLDERS
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment