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
3bb5a9ee
Commit
3bb5a9ee
authored
Nov 04, 2020
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration to fix not consistent data
And add specs to the migration
parent
07bcc6be
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
1 deletion
+51
-1
db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb
...rate/20201104124300_ensure_namespace_settings_creation.rb
+33
-0
db/schema_migrations/20201104124300
db/schema_migrations/20201104124300
+1
-0
db/structure.sql
db/structure.sql
+1
-1
spec/migrations/ensure_namespace_settings_creation_spec.rb
spec/migrations/ensure_namespace_settings_creation_spec.rb
+16
-0
No files found.
db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb
0 → 100644
View file @
3bb5a9ee
# frozen_string_literal: true
class
EnsureNamespaceSettingsCreation
<
ActiveRecord
::
Migration
[
5.2
]
DOWNTIME
=
false
BATCH_SIZE
=
10000
class
Namespace
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'namespaces'
end
def
up
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/20201104124300
0 → 100644
View file @
3bb5a9ee
e17da7eebb6d054a711368369d2b4fa684e96344f845bb7c6b3c89a9b4c4e067
\ No newline at end of file
db/structure.sql
View file @
3bb5a9ee
...
...
@@ -22513,7 +22513,7 @@ ALTER INDEX product_analytics_events_experimental_pkey ATTACH PARTITION gitlab_p
ALTER
INDEX
product_analytics_events_experimental_pkey
ATTACH
PARTITION
gitlab_partitions_static
.
product_analytics_events_experimental_63_pkey
;
CREATE
TRIGGER
table_sync_trigger_ee39a25f9d
AFTER
INSERT
OR
DELETE
OR
UPDATE
ON
audit_events
FOR
EACH
ROW
EXECUTE
PROCEDURE
table_sync_function_2be879775d
();
CREATE
TRIGGER
table_sync_trigger_ee39a25f9d
AFTER
INSERT
OR
DELETE
OR
UPDATE
ON
audit_events
FOR
EACH
ROW
EXECUTE
FUNCTION
table_sync_function_2be879775d
();
ALTER
TABLE
ONLY
chat_names
ADD
CONSTRAINT
fk_00797a2bf9
FOREIGN
KEY
(
service_id
)
REFERENCES
services
(
id
)
ON
DELETE
CASCADE
;
...
...
spec/migrations/ensure_namespace_settings_creation_spec.rb
0 → 100644
View file @
3bb5a9ee
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'/Users/gosia/gitlab-development-kit/gitlab/db/post_migrate/20201104124300_ensure_namespace_settings_creation.rb'
)
RSpec
.
describe
EnsureNamespaceSettingsCreation
do
context
'when there are namespaces without namespace settings'
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:namespace_settings
)
{
table
(
:namespace_settings
)
}
let!
(
:namespace
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org'
)
}
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