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
da7233d4
Commit
da7233d4
authored
Nov 06, 2020
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cr remarks
parent
056cedde
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
5 deletions
+40
-5
db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb
...rate/20201104124300_ensure_namespace_settings_creation.rb
+11
-4
spec/migrations/ensure_namespace_settings_creation_spec.rb
spec/migrations/ensure_namespace_settings_creation_spec.rb
+29
-1
No files found.
db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb
View file @
da7233d4
# frozen_string_literal: true
class
EnsureNamespaceSettingsCreation
<
ActiveRecord
::
Migration
[
5.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
10000
MIGRATION
=
'BackfillNamespaceSettings'
DELAY_INTERVAL
=
2
.
minutes
.
to_i
disable_ddl_transaction!
class
Namespace
<
ActiveRecord
::
Base
include
EachBatch
...
...
@@ -21,12 +27,13 @@ class EnsureNamespaceSettingsCreation < ActiveRecord::Migration[5.2]
private
def
ensure_data_migration
Namespace
.
each_batch
(
of:
BATCH_SIZE
)
do
|
query
|
Namespace
.
each_batch
(
of:
BATCH_SIZE
)
do
|
query
,
index
|
missing_count
=
query
.
where
(
"NOT EXISTS (SELECT 1 FROM namespace_settings WHERE namespace_settings.namespace_id=namespaces.id)"
).
limit
(
1
).
size
if
missing_count
>
0
min
,
max
=
query
.
pluck
(
"MIN(id), MAX(id)"
).
flatten
# we expect low record count so inline execution is fine.
Gitlab
::
BackgroundMigration
::
BackfillNamespaceSettings
.
new
.
perform
(
min
,
max
)
ids_range
=
query
.
pluck
(
"MIN(id), MAX(id)"
).
flatten
migrate_in
(
index
*
DELAY_INTERVAL
,
MIGRATION
,
ids_range
)
end
end
end
...
...
spec/migrations/ensure_namespace_settings_creation_spec.rb
View file @
da7233d4
...
...
@@ -8,9 +8,37 @@ RSpec.describe EnsureNamespaceSettingsCreation do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:namespace_settings
)
{
table
(
:namespace_settings
)
}
let!
(
:namespace
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org'
)
}
let!
(
:namespace_2
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org2'
)
}
it
'migrates namespaces without namespace_settings'
do
expect
{
migrate!
}.
to
change
{
namespace_settings
.
count
}.
from
(
0
).
to
(
1
)
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
2
)
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migrate!
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
2
.
minutes
.
to_i
,
namespace
.
id
,
namespace_2
.
id
)
end
end
end
it
'schedules migrations in batches '
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
2
)
namespace_3
=
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org3'
)
namespace_4
=
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org4'
)
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migrate!
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
2
.
minutes
.
to_i
,
namespace
.
id
,
namespace_2
.
id
)
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
4
.
minutes
.
to_i
,
namespace_3
.
id
,
namespace_4
.
id
)
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