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
f9d95243
Commit
f9d95243
authored
Sep 30, 2021
by
Brett Walker
Committed by
charlie ablett
Nov 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backfill default namespace as User namespace
Changelog: other
parent
d30d4658
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
0 deletions
+96
-0
db/post_migrate/20210930211936_backfill_user_namespace.rb
db/post_migrate/20210930211936_backfill_user_namespace.rb
+24
-0
db/schema_migrations/20210930211936
db/schema_migrations/20210930211936
+1
-0
lib/gitlab/background_migration/backfill_user_namespace.rb
lib/gitlab/background_migration/backfill_user_namespace.rb
+17
-0
spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb
...tlab/background_migration/backfill_user_namespace_spec.rb
+25
-0
spec/migrations/backfill_user_namespace_spec.rb
spec/migrations/backfill_user_namespace_spec.rb
+29
-0
No files found.
db/post_migrate/20210930211936_backfill_user_namespace.rb
0 → 100644
View file @
f9d95243
# frozen_string_literal: true
class
BackfillUserNamespace
<
Gitlab
::
Database
::
Migration
[
1.0
]
MIGRATION
=
'BackfillUserNamespace'
INTERVAL
=
2
.
minutes
BATCH_SIZE
=
10_000
DOWNTIME
=
false
def
up
queue_batched_background_migration
(
MIGRATION
,
:namespaces
,
:id
,
job_interval:
INTERVAL
,
batch_size:
BATCH_SIZE
)
end
def
down
Gitlab
::
Database
::
BackgroundMigration
::
BatchedMigration
.
for_configuration
(
MIGRATION
,
:namespaces
,
:id
,
[])
.
delete_all
end
end
db/schema_migrations/20210930211936
0 → 100644
View file @
f9d95243
3aaf2a4fa834331768e2acc10f67b8d456e70aca9784787e40b55dade7b6f64c
\ No newline at end of file
lib/gitlab/background_migration/backfill_user_namespace.rb
0 → 100644
View file @
f9d95243
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
# Backfills the `namespaces.type` column, replacing any
# instances of `NULL` with `User`
class
BackfillUserNamespace
def
perform
(
start_id
,
stop_id
,
*
args
)
ActiveRecord
::
Base
.
connection
.
execute
(
<<~
SQL
)
UPDATE namespaces SET type = 'User'
WHERE id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
AND type IS NULL
SQL
end
end
end
end
spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb
0 → 100644
View file @
f9d95243
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
BackfillUserNamespace
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
before
do
namespaces
.
create!
(
id:
1
,
name:
'test1'
,
path:
'test1'
,
type:
nil
)
namespaces
.
create!
(
id:
2
,
name:
'test2'
,
path:
'test2'
,
type:
'User'
)
namespaces
.
create!
(
id:
3
,
name:
'test3'
,
path:
'test3'
,
type:
'Group'
)
namespaces
.
create!
(
id:
4
,
name:
'test4'
,
path:
'test4'
,
type:
nil
)
namespaces
.
create!
(
id:
11
,
name:
'test11'
,
path:
'test11'
,
type:
nil
)
end
it
'backfills `type_new` for the selected records'
do
queries
=
ActiveRecord
::
QueryRecorder
.
new
do
migration
.
perform
(
1
,
10
)
end
expect
(
queries
.
count
).
to
be
(
1
)
expect
(
Namespace
.
where
(
type:
'User'
).
count
).
to
eq
3
end
end
spec/migrations/backfill_user_namespace_spec.rb
0 → 100644
View file @
f9d95243
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
BackfillUserNamespace
do
let_it_be
(
:migration
)
{
described_class
::
MIGRATION
}
describe
'#up'
do
it
'schedules background jobs for each batch of namespaces'
do
migrate!
expect
(
migration
).
to
have_scheduled_batched_migration
(
table_name: :namespaces
,
column_name: :id
,
interval:
described_class
::
INTERVAL
)
end
end
describe
'#down'
do
it
'deletes all batched migration records'
do
migrate!
schema_migrate_down!
expect
(
migration
).
not_to
have_scheduled_batched_migration
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