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
c44d5921
Commit
c44d5921
authored
Sep 10, 2020
by
Gosia Ksionek
Committed by
Adam Hegyi
Sep 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure namespace settings are backfilled
parent
96fcb5ba
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
0 deletions
+65
-0
changelogs/unreleased/ensure-db-consistency-after-36321.yml
changelogs/unreleased/ensure-db-consistency-after-36321.yml
+5
-0
db/post_migrate/20200907124300_complete_namespace_settings_migration.rb
...e/20200907124300_complete_namespace_settings_migration.rb
+35
-0
db/schema_migrations/20200907124300
db/schema_migrations/20200907124300
+1
-0
spec/migrations/complete_namespace_settings_migration_spec.rb
.../migrations/complete_namespace_settings_migration_spec.rb
+24
-0
No files found.
changelogs/unreleased/ensure-db-consistency-after-36321.yml
0 → 100644
View file @
c44d5921
---
title
:
Ensure namespace settings are backfilled via migration
merge_request
:
41679
author
:
type
:
other
db/post_migrate/20200907124300_complete_namespace_settings_migration.rb
0 → 100644
View file @
c44d5921
# frozen_string_literal: true
class
CompleteNamespaceSettingsMigration
<
ActiveRecord
::
Migration
[
5.2
]
DOWNTIME
=
false
BATCH_SIZE
=
10000
class
Namespace
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'namespaces'
end
def
up
Gitlab
::
BackgroundMigration
.
steal
(
'BackfillNamespaceSettings'
)
ensure_data_migration
end
def
down
# no-op
end
private
def
ensure_data_migration
Namespace
.
each_batch
(
of:
BATCH_SIZE
)
do
|
query
|
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
)
end
end
end
end
db/schema_migrations/20200907124300
0 → 100644
View file @
c44d5921
2311967a9f68e1a428662e0231752ad0d844063d66cca895211d38f9ae928d94
\ No newline at end of file
spec/migrations/complete_namespace_settings_migration_spec.rb
0 → 100644
View file @
c44d5921
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200907124300_complete_namespace_settings_migration.rb'
)
RSpec
.
describe
CompleteNamespaceSettingsMigration
,
:redis
do
let
(
:migration
)
{
spy
(
'migration'
)
}
context
'when still legacy artifacts exist'
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:namespace_settings
)
{
table
(
:namespace_settings
)
}
let!
(
:namespace
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org'
)
}
it
'steals sidekiq jobs from BackfillNamespaceSettings background migration'
do
expect
(
Gitlab
::
BackgroundMigration
).
to
receive
(
:steal
).
with
(
'BackfillNamespaceSettings'
)
migrate!
end
it
'migrates namespaces without namespace_settings'
do
expect
{
migrate!
}.
to
change
{
namespace_settings
.
count
}.
from
(
0
).
to
(
1
)
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