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
7f6ac436
Commit
7f6ac436
authored
Oct 08, 2021
by
Brett Walker
Committed by
charlie ablett
Nov 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress
parent
531cf8d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
8 deletions
+39
-8
db/post_migrate/20210930211936_backfill_user_namespace.rb
db/post_migrate/20210930211936_backfill_user_namespace.rb
+4
-2
lib/gitlab/background_migration/backfill_user_namespace.rb
lib/gitlab/background_migration/backfill_user_namespace.rb
+35
-6
No files found.
db/post_migrate/20210930211936_backfill_user_namespace.rb
View file @
7f6ac436
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
class
BackfillUserNamespace
<
Gitlab
::
Database
::
Migration
[
1.0
]
class
BackfillUserNamespace
<
Gitlab
::
Database
::
Migration
[
1.0
]
MIGRATION
=
'BackfillUserNamespace'
MIGRATION
=
'BackfillUserNamespace'
INTERVAL
=
2
.
minutes
INTERVAL
=
2
.
minutes
BATCH_SIZE
=
10_000
BATCH_SIZE
=
1_000
SUB_BATCH_SIZE
=
200
DOWNTIME
=
false
DOWNTIME
=
false
def
up
def
up
...
@@ -12,7 +13,8 @@ class BackfillUserNamespace < Gitlab::Database::Migration[1.0]
...
@@ -12,7 +13,8 @@ class BackfillUserNamespace < Gitlab::Database::Migration[1.0]
:namespaces
,
:namespaces
,
:id
,
:id
,
job_interval:
INTERVAL
,
job_interval:
INTERVAL
,
batch_size:
BATCH_SIZE
batch_size:
BATCH_SIZE
,
sub_batch_size:
SUB_BATCH_SIZE
)
)
end
end
...
...
lib/gitlab/background_migration/backfill_user_namespace.rb
View file @
7f6ac436
...
@@ -5,12 +5,41 @@ module Gitlab
...
@@ -5,12 +5,41 @@ module Gitlab
# Backfills the `namespaces.type` column, replacing any
# Backfills the `namespaces.type` column, replacing any
# instances of `NULL` with `User`
# instances of `NULL` with `User`
class
BackfillUserNamespace
class
BackfillUserNamespace
def
perform
(
start_id
,
stop_id
,
*
args
)
include
Gitlab
::
Database
::
DynamicModelHelpers
ActiveRecord
::
Base
.
connection
.
execute
(
<<~
SQL
)
UPDATE namespaces SET type = 'User'
def
perform
(
start_id
,
end_id
,
batch_table
,
batch_column
,
sub_batch_size
)
WHERE id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
parent_batch_relation
=
relation_scoped_to_range
(
batch_table
,
batch_column
,
start_id
,
end_id
)
AND type IS NULL
SQL
parent_batch_relation
.
each_batch
(
column:
batch_column
,
of:
sub_batch_size
)
do
|
sub_batch
|
batch_metrics
.
time_operation
(
:update_all
)
do
sub_batch
.
update_all
(
type:
'User'
)
end
pause_ms
=
0
if
pause_ms
<
0
sleep
(
pause_ms
*
0.001
)
end
# ActiveRecord::Base.connection.execute(<<~SQL)
# UPDATE namespaces SET type = 'User'
# WHERE id BETWEEN #{start_id} AND #{end_id}
# AND type IS NULL
# SQL
end
def
batch_metrics
@batch_metrics
||=
Gitlab
::
Database
::
BackgroundMigration
::
BatchMetrics
.
new
end
private
def
connection
ActiveRecord
::
Base
.
connection
end
def
relation_scoped_to_range
(
source_table
,
source_key_column
,
start_id
,
stop_id
)
define_batchable_model
(
source_table
)
.
where
(
source_key_column
=>
start_id
..
stop_id
)
.
where
(
type:
nil
)
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