...
 
Commits (7)
  • Yorick Peterse's avatar
    Move EE code out of Gitlab::ObjectHierarchy · 3aa92531
    Yorick Peterse authored
    This moves all EE specific code out of Gitlab::ObjectHierarchy and into
    EE::Gitlab::ObjectHierarchy.
    3aa92531
  • Yorick Peterse's avatar
    Move EE code out of Gitlab::PathRegex · 1e3abec7
    Yorick Peterse authored
    This moves all EE code out of Gitlab::PathRegex and into
    EE::Gitlab::PathRegex.
    1e3abec7
  • Yorick Peterse's avatar
    Prepend EE::Gitlab::Regex into Gitlab::Regex · ee14a22e
    Yorick Peterse authored
    This ensures that we modify Gitlab::Regex using EE specific modules the
    same way as we do with other modules/classes.
    ee14a22e
  • Yorick Peterse's avatar
    Backport allow_mirror_update for Chain::Command · 42af0001
    Yorick Peterse authored
    This backports the allow_mirror_update update field for Chain::Command
    from EE to CE. There's no particular reason to keep this in EE. Doing so
    would require refactoring of CE as there currently is no easy way to
    inject new Struct members into the Chain::Command class.
    42af0001
  • Yorick Peterse's avatar
    Move EE code out of Gitlab::UsageData · 81c6ade5
    Yorick Peterse authored
    This moves EE specific code out of Gitlab::UsageData and into
    EE::Gitlab::UsageData. We also remove the overriding of the "CE" string
    with "EE", because EE::Gitlab::UsageData already overrides this with its
    own value.
    81c6ade5
  • Yorick Peterse's avatar
    Backport try_megabytes_to_bytes from EE · c598632b
    Yorick Peterse authored
    EE adds this method to Gitlab::Utils, which is also required by our
    SimpleCov helper. This prevents us from injecting EE modules into
    Gitlab::Utils, because the necessary bits for this are not yet in place.
    
    To work around this we just backport try_megabytes_to_bytes, as there's
    no particular reason to keep this in EE only.
    c598632b
  • Yorick Peterse's avatar
    Move EE code out of two background migrations · b1c86666
    Yorick Peterse authored
    This moves the EE specific queries to EE modules that we prepend into
    the background migrations. This requires some duplication of the SQL
    queries, but there's sadly no way around this.
    b1c86666
# frozen_string_literal: true
module EE
module Gitlab
module BackgroundMigration
module PopulateImportState
extend ::Gitlab::Utils::Override
override :move_attributes_data_to_import_state
def move_attributes_data_to_import_state(start_id, end_id)
Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}")
ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO project_mirror_data (project_id, status, jid, last_update_at, last_successful_update_at, last_error)
SELECT id, import_status, import_jid, mirror_last_update_at, mirror_last_successful_update_at, import_error
FROM projects
WHERE projects.import_status != 'none'
AND projects.id BETWEEN #{start_id} AND #{end_id}
AND NOT EXISTS (
SELECT id
FROM project_mirror_data
WHERE project_id = projects.id
)
SQL
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects
SET import_status = 'none'
WHERE import_status != 'none'
AND id BETWEEN #{start_id} AND #{end_id}
SQL
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module BackgroundMigration
module RollbackImportStateData
extend ::Gitlab::Utils::Override
override :move_attributes_data_to_project
def move_attributes_data_to_project(start_id, end_id)
Rails.logger.info("#{self.class.name} - Moving import attributes data to projects table: #{start_id} - #{end_id}")
if ::Gitlab::Database.mysql?
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects, project_mirror_data
SET
projects.import_status = project_mirror_data.status,
projects.import_jid = project_mirror_data.jid,
projects.mirror_last_update_at = project_mirror_data.last_update_at,
projects.mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
projects.import_error = project_mirror_data.last_error
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
SQL
else
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects
SET
import_status = project_mirror_data.status,
import_jid = project_mirror_data.jid,
mirror_last_update_at = project_mirror_data.last_update_at,
mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
import_error = project_mirror_data.last_error
FROM project_mirror_data
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
SQL
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module ObjectHierarchy
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module PathRegex
extend ActiveSupport::Concern
class_methods do
def saml_callback_regex
@saml_callback_regex ||= %r(\A\/groups\/(?<group>#{full_namespace_route_regex})\/\-\/saml\/callback\z).freeze
end
end
end
end
end
......@@ -3,41 +3,45 @@
module EE
module Gitlab
module Regex
def environment_scope_regex_chars
"#{environment_name_regex_chars}\\*"
end
extend ActiveSupport::Concern
def environment_scope_regex
@environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze
end
class_methods do
def environment_scope_regex_chars
"#{environment_name_regex_chars}\\*"
end
def environment_scope_regex_message
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
end
def environment_scope_regex
@environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze
end
def package_name_regex
@package_name_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.]*)\z}.freeze
end
def environment_scope_regex_message
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
end
def maven_path_regex
@maven_path_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.\+]*)\z}.freeze
end
def package_name_regex
@package_name_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.]*)\z}.freeze
end
def maven_app_name_regex
@maven_app_name_regex ||= /\A[\w\-\.]+\z/.freeze
end
def maven_path_regex
@maven_path_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.\+]*)\z}.freeze
end
def maven_app_group_regex
maven_app_name_regex
end
def maven_app_name_regex
@maven_app_name_regex ||= /\A[\w\-\.]+\z/.freeze
end
def feature_flag_regex
/\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/
end
def maven_app_group_regex
maven_app_name_regex
end
def feature_flag_regex
/\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/
end
def feature_flag_regex_message
"can contain only lowercase letters, digits, '_' and '-'. " \
"Must start with a letter, and cannot end with '-' or '_'"
def feature_flag_regex_message
"can contain only lowercase letters, digits, '_' and '-'. " \
"Must start with a letter, and cannot end with '-' or '_'"
end
end
end
end
......
This diff is collapsed.
......@@ -15,8 +15,8 @@ module Gitlab
Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}")
ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO project_mirror_data (project_id, status, jid, last_update_at, last_successful_update_at, last_error)
SELECT id, import_status, import_jid, mirror_last_update_at, mirror_last_successful_update_at, import_error
INSERT INTO project_mirror_data (project_id, status, jid, last_error)
SELECT id, import_status, import_jid, import_error
FROM projects
WHERE projects.import_status != 'none'
AND projects.id BETWEEN #{start_id} AND #{end_id}
......@@ -37,3 +37,5 @@ module Gitlab
end
end
end
Gitlab::BackgroundMigration::PopulateImportState.prepend(EE::Gitlab::BackgroundMigration::PopulateImportState)
......@@ -18,8 +18,6 @@ module Gitlab
SET
projects.import_status = project_mirror_data.status,
projects.import_jid = project_mirror_data.jid,
projects.mirror_last_update_at = project_mirror_data.last_update_at,
projects.mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
projects.import_error = project_mirror_data.last_error
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
......@@ -30,8 +28,6 @@ module Gitlab
SET
import_status = project_mirror_data.status,
import_jid = project_mirror_data.jid,
mirror_last_update_at = project_mirror_data.last_update_at,
mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
import_error = project_mirror_data.last_error
FROM project_mirror_data
WHERE project_mirror_data.project_id = projects.id
......@@ -42,3 +38,5 @@ module Gitlab
end
end
end
Gitlab::BackgroundMigration::RollbackImportStateData.prepend(EE::Gitlab::BackgroundMigration::RollbackImportStateData)
......@@ -11,10 +11,7 @@ module Gitlab
:trigger_request, :schedule, :merge_request,
:ignore_skip_ci, :save_incompleted,
:seeds_block, :variables_attributes, :push_options,
:chat_data,
# EE specific
:allow_mirror_update
:chat_data, :allow_mirror_update
) do
include Gitlab::Utils::StrongMemoize
......
......@@ -39,12 +39,6 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
# Returns a relation that includes the ancestors_base set of objects
# and all their ancestors (recursively).
#
......@@ -179,3 +173,5 @@ module Gitlab
end
end
end
Gitlab::ObjectHierarchy.prepend(EE::Gitlab::ObjectHierarchy)
......@@ -233,10 +233,6 @@ module Gitlab
}x
end
def saml_callback_regex
@saml_callback_regex ||= %r(\A\/groups\/(?<group>#{full_namespace_route_regex})\/\-\/saml\/callback\z).freeze
end
private
def single_line_regexp(regex)
......@@ -246,3 +242,5 @@ module Gitlab
end
end
end
Gitlab::PathRegex.prepend(EE::Gitlab::PathRegex)
......@@ -3,7 +3,6 @@
module Gitlab
module Regex
extend self
extend EE::Gitlab::Regex # rubocop: disable Cop/InjectEnterpriseEditionModule
def namespace_name_regex
@namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
......@@ -108,3 +107,5 @@ module Gitlab
end
end
end
Gitlab::Regex.prepend(EE::Gitlab::Regex)
......@@ -5,8 +5,6 @@ module Gitlab
APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze
class << self
prepend EE::Gitlab::UsageData # rubocop: disable Cop/InjectEnterpriseEditionModule
def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
end
......@@ -31,7 +29,7 @@ module Gitlab
installation_type: Gitlab::INSTALLATION_TYPE,
active_user_count: count(User.active),
recorded_at: Time.now,
edition: 'EE'
edition: 'CE'
}
usage_data
......@@ -192,3 +190,5 @@ module Gitlab
end
end
end
Gitlab::UsageData.prepend(EE::Gitlab::UsageData)
......@@ -104,7 +104,6 @@ module Gitlab
nil
end
# EE below
def try_megabytes_to_bytes(size)
Integer(size).megabytes
rescue ArgumentError
......
......@@ -213,4 +213,22 @@ describe Gitlab::Utils do
expect(subject[:variables].first[:key]).to eq('VAR1')
end
end
describe '.try_megabytes_to_bytes' do
context 'when the size can be converted to megabytes' do
it 'returns the size in megabytes' do
size = described_class.try_megabytes_to_bytes(1)
expect(size).to eq(1.megabytes)
end
end
context 'when the size can not be converted to megabytes' do
it 'returns the input size' do
size = described_class.try_megabytes_to_bytes('foo')
expect(size).to eq('foo')
end
end
end
end