Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
863b7c32
Commit
863b7c32
authored
Aug 16, 2021
by
Tetiana Chupryna
Committed by
Mayra Cabrera
Aug 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SecuritySetting to Projects
parent
5f965193
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
0 deletions
+158
-0
db/post_migrate/20210730170823_schedule_security_setting_creation.rb
...rate/20210730170823_schedule_security_setting_creation.rb
+26
-0
db/schema_migrations/20210730170823
db/schema_migrations/20210730170823
+1
-0
ee/lib/ee/gitlab/background_migration/create_security_setting.rb
...ee/gitlab/background_migration/create_security_setting.rb
+38
-0
ee/spec/lib/ee/gitlab/background_migration/create_security_setting_spec.rb
...tlab/background_migration/create_security_setting_spec.rb
+21
-0
lib/gitlab/background_migration/create_security_setting.rb
lib/gitlab/background_migration/create_security_setting.rb
+14
-0
spec/migrations/schedule_security_setting_creation_spec.rb
spec/migrations/schedule_security_setting_creation_spec.rb
+58
-0
No files found.
db/post_migrate/20210730170823_schedule_security_setting_creation.rb
0 → 100644
View file @
863b7c32
# frozen_string_literal: true
class
ScheduleSecuritySettingCreation
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
MIGRATION
=
'CreateSecuritySetting'
BATCH_SIZE
=
1000
INTERVAL
=
5
.
minutes
.
to_i
disable_ddl_transaction!
def
up
return
unless
Gitlab
.
ee?
# Security Settings available only in EE version
queue_background_migration_jobs_by_range_at_intervals
(
define_batchable_model
(
'projects'
),
MIGRATION
,
INTERVAL
,
batch_size:
BATCH_SIZE
)
end
# We're adding data so no need for rollback
def
down
end
end
db/schema_migrations/20210730170823
0 → 100644
View file @
863b7c32
33b260626d65347a80240ffdce5f9e2abfc578e8151ed41f1ca9b16ef2654853
\ No newline at end of file
ee/lib/ee/gitlab/background_migration/create_security_setting.rb
0 → 100644
View file @
863b7c32
# frozen_string_literal: true
module
EE
module
Gitlab
module
BackgroundMigration
module
CreateSecuritySetting
extend
::
Gitlab
::
Utils
::
Override
class
Project
<
ActiveRecord
::
Base
self
.
table_name
=
'projects'
has_one
:security_setting
,
class_name:
'ProjectSecuritySetting'
scope
:without_security_settings
,
->
{
left_joins
(
:security_setting
).
where
(
project_security_settings:
{
project_id:
nil
})
}
end
class
ProjectSecuritySetting
<
ActiveRecord
::
Base
self
.
table_name
=
'project_security_settings'
belongs_to
:project
,
inverse_of: :security_setting
end
override
:perform
def
perform
(
from_id
,
to_id
)
select_from
=
Project
.
without_security_settings
.
where
(
id:
from_id
..
to_id
).
select
(
'id, NOW(), NOW()'
).
to_sql
ActiveRecord
::
Base
.
connection_pool
.
with_connection
do
|
connection
|
connection
.
execute
<<~
SQL
INSERT INTO project_security_settings (project_id, created_at, updated_at)
#{
select_from
}
ON CONFLICT (project_id) DO NOTHING
SQL
end
end
end
end
end
end
ee/spec/lib/ee/gitlab/background_migration/create_security_setting_spec.rb
0 → 100644
View file @
863b7c32
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
CreateSecuritySetting
do
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:settings
)
{
table
(
:project_security_settings
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
describe
'#perform'
do
it
'adds setting object for existing projects'
do
namespace
=
namespaces
.
create!
(
name:
'test'
,
path:
'test'
)
projects
.
create!
(
id:
12
,
namespace_id:
namespace
.
id
,
name:
'gitlab'
,
path:
'gitlab'
)
projects
.
create!
(
id:
13
,
namespace_id:
namespace
.
id
,
name:
'sec_gitlab'
,
path:
'sec_gitlab'
)
projects
.
create!
(
id:
14
,
namespace_id:
namespace
.
id
,
name:
'my_gitlab'
,
path:
'my_gitlab'
)
settings
.
create!
(
project_id:
13
)
expect
{
described_class
.
new
.
perform
(
12
,
14
)
}.
to
change
{
settings
.
count
}.
from
(
1
).
to
(
3
)
end
end
end
lib/gitlab/background_migration/create_security_setting.rb
0 → 100644
View file @
863b7c32
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
# This class doesn't create SecuritySetting
# as this feature exists only in EE
class
CreateSecuritySetting
def
perform
(
_from_id
,
_to_id
)
end
end
end
end
Gitlab
::
BackgroundMigration
::
CreateSecuritySetting
.
prepend_mod_with
(
'Gitlab::BackgroundMigration::CreateSecuritySetting'
)
spec/migrations/schedule_security_setting_creation_spec.rb
0 → 100644
View file @
863b7c32
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
ScheduleSecuritySettingCreation
,
:sidekiq
do
describe
'#up'
do
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
context
'for EE version'
do
before
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
2
)
allow
(
Gitlab
).
to
receive
(
:ee?
).
and_return
(
true
)
end
it
'schedules background migration job'
do
namespace
=
namespaces
.
create!
(
name:
'test'
,
path:
'test'
)
projects
.
create!
(
id:
12
,
namespace_id:
namespace
.
id
,
name:
'red'
,
path:
'red'
)
projects
.
create!
(
id:
13
,
namespace_id:
namespace
.
id
,
name:
'green'
,
path:
'green'
)
projects
.
create!
(
id:
14
,
namespace_id:
namespace
.
id
,
name:
'blue'
,
path:
'blue'
)
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migrate!
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
5
.
minutes
,
12
,
13
)
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
10
.
minutes
,
14
,
14
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
2
)
end
end
end
end
context
'for FOSS version'
do
before
do
allow
(
Gitlab
).
to
receive
(
:ee?
).
and_return
(
false
)
end
it
'does not schedule any jobs'
do
namespace
=
namespaces
.
create!
(
name:
'test'
,
path:
'test'
)
projects
.
create!
(
id:
12
,
namespace_id:
namespace
.
id
,
name:
'red'
,
path:
'red'
)
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migrate!
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
0
)
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment