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
5c3867e1
Commit
5c3867e1
authored
Apr 24, 2018
by
Zeger-Jan van de Weg
Committed by
Toon Claes
Jun 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert migration dropping columns in one release"
This reverts commit a2bcb0bec1de4a854f77656be9ca023e4b8b1a0e.
parent
13a8ad60
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
4 deletions
+142
-4
db/schema.rb
db/schema.rb
+0
-4
ee/db/post_migrate/20180417102933_drop_repository_storage_events_for_geo_events.rb
...17102933_drop_repository_storage_events_for_geo_events.rb
+87
-0
ee/spec/migrations/drop_repository_storage_events_for_geo_events_spec.rb
...ons/drop_repository_storage_events_for_geo_events_spec.rb
+55
-0
No files found.
db/schema.rb
View file @
5c3867e1
...
...
@@ -1063,7 +1063,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table
"geo_hashed_storage_migrated_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
text
"repository_storage_name"
,
null:
false
t
.
text
"repository_storage_path"
t
.
text
"old_disk_path"
,
null:
false
t
.
text
"new_disk_path"
,
null:
false
t
.
text
"old_wiki_disk_path"
,
null:
false
...
...
@@ -1175,7 +1174,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table
"geo_repository_created_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
text
"repository_storage_name"
,
null:
false
t
.
text
"repository_storage_path"
t
.
text
"repo_path"
,
null:
false
t
.
text
"wiki_path"
t
.
text
"project_name"
,
null:
false
...
...
@@ -1186,7 +1184,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table
"geo_repository_deleted_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
text
"repository_storage_name"
,
null:
false
t
.
text
"repository_storage_path"
t
.
text
"deleted_path"
,
null:
false
t
.
text
"deleted_wiki_path"
t
.
text
"deleted_project_name"
,
null:
false
...
...
@@ -1197,7 +1194,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table
"geo_repository_renamed_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
text
"repository_storage_name"
,
null:
false
t
.
text
"repository_storage_path"
t
.
text
"old_path_with_namespace"
,
null:
false
t
.
text
"new_path_with_namespace"
,
null:
false
t
.
text
"old_wiki_path_with_namespace"
,
null:
false
...
...
ee/db/post_migrate/20180417102933_drop_repository_storage_events_for_geo_events.rb
0 → 100644
View file @
5c3867e1
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
DropRepositoryStorageEventsForGeoEvents
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
5_000
TABLES
=
%i(geo_hashed_storage_migrated_events geo_repository_created_events
geo_repository_deleted_events geo_repository_renamed_events)
def
up
TABLES
.
each
{
|
t
|
remove_column
(
t
,
:repository_storage_path
)
}
end
def
down
TABLES
.
each
{
|
t
|
add_column
(
t
,
:repository_storage_path
,
:text
)
}
add_shard_path
end
private
def
add_shard_path
TABLES
.
each
do
|
t
|
min_id
=
0
loop
do
newest
=
newest_entry
(
t
)
break
unless
newest
break
if
newest
[
'repository_storage_path'
].
present?
new_batch
=
batch
(
t
,
min_id
)
update_batch
(
t
,
new_batch
)
min_id
=
new_batch
.
last
.
to_i
end
change_column_null
(
t
,
:repository_storage_path
,
true
)
end
end
def
newest_entry
(
table
)
execute
(
<<~
SQL
SELECT id, repository_storage_path
FROM
#{
table
}
ORDER BY id DESC
LIMIT 1;
SQL
).
first
end
def
batch
(
table
,
min_id
)
execute
(
<<~
SQL
SELECT id
FROM
#{
table
}
WHERE id >
#{
min_id
}
ORDER BY id ASC
LIMIT
#{
BATCH_SIZE
}
;
SQL
).
map
{
|
row
|
row
[
'id'
]
}
end
def
update_batch
(
table
,
ids
)
execute
(
<<~
SQL
UPDATE
#{
table
}
SET repository_storage_path =
CASE repository_storage_name
#{
case_statements
}
END
WHERE id IN (
#{
ids
.
join
(
','
)
}
)
SQL
)
end
def
case_statements
statement
=
""
Gitlab
.
config
.
repositories
.
storages
.
each
do
|
shard
,
data
|
statement
<<
"WHEN '
#{
shard
}
' THEN '
#{
data
.
legacy_disk_path
}
'
\n
"
end
statement
end
end
ee/spec/migrations/drop_repository_storage_events_for_geo_events_spec.rb
0 → 100644
View file @
5c3867e1
# encoding: utf-8
require
'spec_helper'
require
Rails
.
root
.
join
(
'ee'
,
'db'
,
'post_migrate'
,
'20180417102933_drop_repository_storage_events_for_geo_events.rb'
)
describe
DropRepositoryStorageEventsForGeoEvents
,
:migration
do
let
(
:migration
)
{
described_class
.
new
}
describe
'#up'
do
before
do
migration
.
up
end
it
'dropped the repository_storage_path column'
do
described_class
::
TABLES
.
each
do
|
table_name
|
columns
=
table
(
table_name
).
columns
.
map
(
&
:name
)
expect
(
columns
).
not_to
include
(
"repository_storage_path"
)
end
end
end
describe
'#down'
do
let
(
:event_name
)
{
:geo_repository_created_event
}
before
do
described_class
.
const_set
(
:BATCH_SIZE
,
1
)
Gitlab
.
config
.
repositories
.
storages
.
each
do
|
name
,
_
|
described_class
.
execute
(
<<~
SQL
INSERT INTO
#{
event_name
}
s (project_id, project_name, repository_storage_name, repo_path)
VALUES (1, 'mepmep', '
#{
name
}
', 'path/to/gitlab-org')
SQL
)
end
migration
.
down
reset_column_in_all_models
end
it
'created the repository_storage_path column'
do
described_class
::
TABLES
.
each
do
|
table_name
|
columns
=
table
(
table_name
).
columns
.
map
(
&
:name
)
expect
(
columns
).
to
include
(
"repository_storage_path"
)
end
null_columns
=
described_class
.
execute
(
"SELECT COUNT(*) FROM
#{
event_name
}
s WHERE repository_storage_path IS NULL;"
)
.
first
[
'count'
]
expect
(
null_columns
.
to_i
).
to
be
(
0
)
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