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
88967ac4
Commit
88967ac4
authored
May 21, 2021
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't raise an error if output directory already exists
parent
73a754e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
12 deletions
+8
-12
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+1
-3
spec/tasks/gitlab/db_rake_spec.rb
spec/tasks/gitlab/db_rake_spec.rb
+7
-9
No files found.
lib/tasks/gitlab/db.rake
View file @
88967ac4
...
@@ -240,9 +240,7 @@ namespace :gitlab do
...
@@ -240,9 +240,7 @@ namespace :gitlab do
desc
'Run migrations with instrumentation'
desc
'Run migrations with instrumentation'
task
migration_testing: :environment
do
task
migration_testing: :environment
do
result_dir
=
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
RESULT_DIR
result_dir
=
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
RESULT_DIR
raise
"Directory exists already, won't overwrite:
#{
result_dir
}
"
if
File
.
exist?
(
result_dir
)
FileUtils
.
mkdir_p
(
result_dir
)
Dir
.
mkdir
(
result_dir
)
verbose_was
=
ActiveRecord
::
Migration
.
verbose
verbose_was
=
ActiveRecord
::
Migration
.
verbose
ActiveRecord
::
Migration
.
verbose
=
true
ActiveRecord
::
Migration
.
verbose
=
true
...
...
spec/tasks/gitlab/db_rake_spec.rb
View file @
88967ac4
...
@@ -306,7 +306,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
...
@@ -306,7 +306,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
let
(
:all_migrations
)
{
[
double
(
'migration1'
,
version:
1
),
pending_migration
]
}
let
(
:all_migrations
)
{
[
double
(
'migration1'
,
version:
1
),
pending_migration
]
}
let
(
:pending_migration
)
{
double
(
'migration2'
,
version:
2
)
}
let
(
:pending_migration
)
{
double
(
'migration2'
,
version:
2
)
}
let
(
:filename
)
{
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
STATS_FILENAME
}
let
(
:filename
)
{
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
STATS_FILENAME
}
let
!
(
:directory
)
{
Dir
.
mktmpdir
}
let
(
:result_dir
)
{
Dir
.
mktmpdir
}
let
(
:observations
)
{
%w[some data]
}
let
(
:observations
)
{
%w[some data]
}
before
do
before
do
...
@@ -316,19 +316,17 @@ RSpec.describe 'gitlab:db namespace rake task' do
...
@@ -316,19 +316,17 @@ RSpec.describe 'gitlab:db namespace rake task' do
allow
(
instrumentation
).
to
receive
(
:observe
).
and_yield
allow
(
instrumentation
).
to
receive
(
:observe
).
and_yield
allow
(
Dir
).
to
receive
(
:mkdir
)
stub_const
(
'Gitlab::Database::Migrations::Instrumentation::RESULT_DIR'
,
result_dir
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
directory
).
and_return
(
false
)
stub_const
(
'Gitlab::Database::Migrations::Instrumentation::RESULT_DIR'
,
directory
)
end
end
after
do
after
do
FileUtils
.
rm_rf
(
[
directory
]
)
FileUtils
.
rm_rf
(
result_dir
)
end
end
it
'
fails when the directory already exists
'
do
it
'
creates result directory when one does not exist
'
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
directory
).
and_return
(
true
)
FileUtils
.
rm_rf
(
result_dir
)
expect
{
subject
}.
to
raise_error
(
/Directory exists/
)
expect
{
subject
}.
to
change
{
Dir
.
exist?
(
result_dir
)
}.
from
(
false
).
to
(
true
)
end
end
it
'instruments the pending migration'
do
it
'instruments the pending migration'
do
...
@@ -346,7 +344,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
...
@@ -346,7 +344,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
it
'writes observations out to JSON file'
do
it
'writes observations out to JSON file'
do
subject
subject
expect
(
File
.
read
(
File
.
join
(
directory
,
filename
))).
to
eq
(
observations
.
to_json
)
expect
(
File
.
read
(
File
.
join
(
result_dir
,
filename
))).
to
eq
(
observations
.
to_json
)
end
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