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
28ac2d30
Commit
28ac2d30
authored
Jul 03, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old migrations and specs
This removes old migrations that violate the FactoriesinMigrationSpecs cop
parent
851d19c2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
0 additions
and
246 deletions
+0
-246
db/post_migrate/20180202111106_remove_project_labels_group_id.rb
..._migrate/20180202111106_remove_project_labels_group_id.rb
+0
-19
lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
...kground_migration/migrate_system_uploads_to_new_folder.rb
+0
-29
lib/gitlab/background_migration/move_personal_snippet_files.rb
...itlab/background_migration/move_personal_snippet_files.rb
+0
-82
spec/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder_spec.rb
...nd_migration/migrate_system_uploads_to_new_folder_spec.rb
+0
-21
spec/lib/gitlab/background_migration/move_personal_snippet_files_spec.rb
.../background_migration/move_personal_snippet_files_spec.rb
+0
-74
spec/migrations/remove_project_labels_group_id_spec.rb
spec/migrations/remove_project_labels_group_id_spec.rb
+0
-21
No files found.
db/post_migrate/20180202111106_remove_project_labels_group_id.rb
deleted
100644 → 0
View file @
851d19c2
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
RemoveProjectLabelsGroupId
<
ActiveRecord
::
Migration
[
4.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
update_column_in_batches
(
:labels
,
:group_id
,
nil
)
do
|
table
,
query
|
query
.
where
(
table
[
:type
].
eq
(
'ProjectLabel'
).
and
(
table
[
:group_id
].
not_eq
(
nil
)))
end
end
def
down
end
end
lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
deleted
100644 → 0
View file @
851d19c2
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module
Gitlab
module
BackgroundMigration
class
MigrateSystemUploadsToNewFolder
include
Gitlab
::
Database
::
MigrationHelpers
attr_reader
:old_folder
,
:new_folder
class
Upload
<
ActiveRecord
::
Base
self
.
table_name
=
'uploads'
include
EachBatch
end
def
perform
(
old_folder
,
new_folder
)
replace_sql
=
replace_sql
(
uploads
[
:path
],
old_folder
,
new_folder
)
affected_uploads
=
Upload
.
where
(
uploads
[
:path
].
matches
(
"
#{
old_folder
}
%"
))
affected_uploads
.
each_batch
do
|
batch
|
batch
.
update_all
(
"path =
#{
replace_sql
}
"
)
end
end
def
uploads
Arel
::
Table
.
new
(
'uploads'
)
end
end
end
end
lib/gitlab/background_migration/move_personal_snippet_files.rb
deleted
100644 → 0
View file @
851d19c2
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module
Gitlab
module
BackgroundMigration
class
MovePersonalSnippetFiles
delegate
:select_all
,
:execute
,
:quote_string
,
to: :connection
def
perform
(
relative_source
,
relative_destination
)
@source_relative_location
=
relative_source
@destination_relative_location
=
relative_destination
move_personal_snippet_files
end
def
move_personal_snippet_files
query
=
"SELECT uploads.path, uploads.model_id FROM uploads "
\
"INNER JOIN snippets ON snippets.id = uploads.model_id WHERE uploader = 'PersonalFileUploader'"
select_all
(
query
).
each
do
|
upload
|
secret
=
upload
[
'path'
].
split
(
'/'
)[
0
]
file_name
=
upload
[
'path'
].
split
(
'/'
)[
1
]
move_file
(
upload
[
'model_id'
],
secret
,
file_name
)
update_markdown
(
upload
[
'model_id'
],
secret
,
file_name
)
end
end
def
move_file
(
snippet_id
,
secret
,
file_name
)
source_dir
=
File
.
join
(
base_directory
,
@source_relative_location
,
snippet_id
.
to_s
,
secret
)
destination_dir
=
File
.
join
(
base_directory
,
@destination_relative_location
,
snippet_id
.
to_s
,
secret
)
source_file_path
=
File
.
join
(
source_dir
,
file_name
)
destination_file_path
=
File
.
join
(
destination_dir
,
file_name
)
unless
File
.
exist?
(
source_file_path
)
say
"Source file `
#{
source_file_path
}
` doesn't exist. Skipping."
return
end
say
"Moving file
#{
source_file_path
}
->
#{
destination_file_path
}
"
FileUtils
.
mkdir_p
(
destination_dir
)
FileUtils
.
move
(
source_file_path
,
destination_file_path
)
end
def
update_markdown
(
snippet_id
,
secret
,
file_name
)
source_markdown_path
=
File
.
join
(
@source_relative_location
,
snippet_id
.
to_s
,
secret
,
file_name
)
destination_markdown_path
=
File
.
join
(
@destination_relative_location
,
snippet_id
.
to_s
,
secret
,
file_name
)
source_markdown
=
"](
#{
source_markdown_path
}
)"
destination_markdown
=
"](
#{
destination_markdown_path
}
)"
quoted_source
=
quote_string
(
source_markdown
)
quoted_destination
=
quote_string
(
destination_markdown
)
execute
(
"UPDATE snippets "
\
"SET description = replace(snippets.description, '
#{
quoted_source
}
', '
#{
quoted_destination
}
'), description_html = NULL "
\
"WHERE id =
#{
snippet_id
}
"
)
query
=
"SELECT id, note FROM notes WHERE noteable_id =
#{
snippet_id
}
"
\
"AND noteable_type = 'Snippet' AND note IS NOT NULL"
select_all
(
query
).
each
do
|
note
|
text
=
note
[
'note'
].
gsub
(
source_markdown
,
destination_markdown
)
quoted_text
=
quote_string
(
text
)
execute
(
"UPDATE notes SET note = '
#{
quoted_text
}
', note_html = NULL WHERE id =
#{
note
[
'id'
]
}
"
)
end
end
def
base_directory
File
.
join
(
Rails
.
root
,
'public'
)
end
def
connection
ActiveRecord
::
Base
.
connection
end
def
say
(
message
)
Rails
.
logger
.
debug
(
message
)
end
end
end
end
spec/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder_spec.rb
deleted
100644 → 0
View file @
851d19c2
require
'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe
Gitlab
::
BackgroundMigration
::
MigrateSystemUploadsToNewFolder
,
:delete
do
let
(
:migration
)
{
described_class
.
new
}
before
do
allow
(
migration
).
to
receive
(
:logger
).
and_return
(
Logger
.
new
(
nil
))
end
describe
'#perform'
do
it
'renames the path of system-uploads'
do
upload
=
create
(
:upload
,
model:
create
(
:project
),
path:
'uploads/system/project/avatar.jpg'
)
migration
.
perform
(
'uploads/system/'
,
'uploads/-/system/'
)
expect
(
upload
.
reload
.
path
).
to
eq
(
'uploads/-/system/project/avatar.jpg'
)
end
end
end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
spec/lib/gitlab/background_migration/move_personal_snippet_files_spec.rb
deleted
100644 → 0
View file @
851d19c2
require
'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe
Gitlab
::
BackgroundMigration
::
MovePersonalSnippetFiles
do
let
(
:test_dir
)
{
File
.
join
(
Rails
.
root
,
'tmp'
,
'tests'
,
'move_snippet_files_test'
)
}
let
(
:old_uploads_dir
)
{
File
.
join
(
'uploads'
,
'system'
,
'personal_snippet'
)
}
let
(
:new_uploads_dir
)
{
File
.
join
(
'uploads'
,
'-'
,
'system'
,
'personal_snippet'
)
}
let
(
:snippet
)
do
snippet
=
create
(
:personal_snippet
)
create_upload_for_snippet
(
snippet
)
snippet
.
update!
(
description:
markdown_linking_file
(
snippet
))
snippet
end
let
(
:migration
)
{
described_class
.
new
}
before
do
allow
(
migration
).
to
receive
(
:base_directory
)
{
test_dir
}
end
describe
'#perform'
do
it
'moves the file on the disk'
do
expected_path
=
File
.
join
(
test_dir
,
new_uploads_dir
,
snippet
.
id
.
to_s
,
"secret
#{
snippet
.
id
}
"
,
'upload.txt'
)
migration
.
perform
(
old_uploads_dir
,
new_uploads_dir
)
expect
(
File
.
exist?
(
expected_path
)).
to
be_truthy
end
it
'updates the markdown of the snippet'
do
expected_path
=
File
.
join
(
new_uploads_dir
,
snippet
.
id
.
to_s
,
"secret
#{
snippet
.
id
}
"
,
'upload.txt'
)
expected_markdown
=
"[an upload](
#{
expected_path
}
)"
migration
.
perform
(
old_uploads_dir
,
new_uploads_dir
)
expect
(
snippet
.
reload
.
description
).
to
eq
(
expected_markdown
)
end
it
'updates the markdown of notes'
do
expected_path
=
File
.
join
(
new_uploads_dir
,
snippet
.
id
.
to_s
,
"secret
#{
snippet
.
id
}
"
,
'upload.txt'
)
expected_markdown
=
"with [an upload](
#{
expected_path
}
)"
note
=
create
(
:note_on_personal_snippet
,
noteable:
snippet
,
note:
"with
#{
markdown_linking_file
(
snippet
)
}
"
)
migration
.
perform
(
old_uploads_dir
,
new_uploads_dir
)
expect
(
note
.
reload
.
note
).
to
eq
(
expected_markdown
)
end
end
def
create_upload_for_snippet
(
snippet
)
snippet_path
=
path_for_file_in_snippet
(
snippet
)
path
=
File
.
join
(
old_uploads_dir
,
snippet
.
id
.
to_s
,
snippet_path
)
absolute_path
=
File
.
join
(
test_dir
,
path
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
absolute_path
))
FileUtils
.
touch
(
absolute_path
)
create
(
:upload
,
model:
snippet
,
path:
snippet_path
,
uploader:
PersonalFileUploader
)
end
def
path_for_file_in_snippet
(
snippet
)
secret
=
"secret
#{
snippet
.
id
}
"
filename
=
'upload.txt'
File
.
join
(
secret
,
filename
)
end
def
markdown_linking_file
(
snippet
)
path
=
File
.
join
(
old_uploads_dir
,
snippet
.
id
.
to_s
,
path_for_file_in_snippet
(
snippet
))
"[an upload](
#{
path
}
)"
end
end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
spec/migrations/remove_project_labels_group_id_spec.rb
deleted
100644 → 0
View file @
851d19c2
# encoding: utf-8
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180202111106_remove_project_labels_group_id.rb'
)
describe
RemoveProjectLabelsGroupId
,
:delete
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:group
)
{
create
(
:group
)
}
# rubocop:disable RSpec/FactoriesInMigrationSpecs
let!
(
:project_label
)
{
create
(
:label
,
group_id:
group
.
id
)
}
# rubocop:disable RSpec/FactoriesInMigrationSpecs
let!
(
:group_label
)
{
create
(
:group_label
)
}
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe
'#up'
do
it
'updates the project labels group ID'
do
expect
{
migration
.
up
}.
to
change
{
project_label
.
reload
.
group_id
}.
to
(
nil
)
end
it
'keeps the group labels group ID'
do
expect
{
migration
.
up
}.
not_to
change
{
group_label
.
reload
.
group_id
}
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