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
940fe552
Commit
940fe552
authored
Apr 22, 2021
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write output files to a directory
To make it easier to artifact more files
parent
eb16b8b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
14 deletions
+21
-14
lib/gitlab/database/migrations/instrumentation.rb
lib/gitlab/database/migrations/instrumentation.rb
+3
-0
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+6
-4
spec/tasks/gitlab/db_rake_spec.rb
spec/tasks/gitlab/db_rake_spec.rb
+12
-10
No files found.
lib/gitlab/database/migrations/instrumentation.rb
View file @
940fe552
...
...
@@ -4,6 +4,9 @@ module Gitlab
module
Database
module
Migrations
class
Instrumentation
RESULT_DIR
=
Rails
.
root
.
join
(
'tmp'
,
'migration-testing'
).
freeze
STATS_FILENAME
=
'migration-stats.json'
attr_reader
:observations
def
initialize
(
observers
=
::
Gitlab
::
Database
::
Migrations
::
Observers
.
all_observers
)
...
...
lib/tasks/gitlab/db.rake
View file @
940fe552
...
...
@@ -217,9 +217,11 @@ namespace :gitlab do
end
desc
'Run migrations with instrumentation'
task
:migration_testing
,
[
:result_file
]
=>
:environment
do
|
_
,
args
|
result_file
=
args
[
:result_file
]
||
raise
(
"Please specify result_file argument"
)
raise
"File exists already, won't overwrite:
#{
result_file
}
"
if
File
.
exist?
(
result_file
)
task
migration_testing: :environment
do
result_dir
=
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
RESULT_DIR
raise
"Directory exists already, won't overwrite:
#{
result_dir
}
"
if
File
.
exist?
(
result_dir
)
Dir
.
mkdir
(
result_dir
)
verbose_was
=
ActiveRecord
::
Migration
.
verbose
ActiveRecord
::
Migration
.
verbose
=
true
...
...
@@ -240,7 +242,7 @@ namespace :gitlab do
end
ensure
if
instrumentation
File
.
open
(
result_file
,
'wb+'
)
do
|
io
|
File
.
open
(
File
.
join
(
result_dir
,
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
STATS_FILENAME
)
,
'wb+'
)
do
|
io
|
io
<<
instrumentation
.
observations
.
to_json
end
end
...
...
spec/tasks/gitlab/db_rake_spec.rb
View file @
940fe552
...
...
@@ -298,15 +298,15 @@ RSpec.describe 'gitlab:db namespace rake task' do
end
describe
'#migrate_with_instrumentation'
do
subject
{
run_rake_task
(
'gitlab:db:migration_testing'
,
"[
#{
filename
}
]"
)
}
subject
{
run_rake_task
(
'gitlab:db:migration_testing'
)
}
let
(
:ctx
)
{
double
(
'ctx'
,
migrations:
all_migrations
,
schema_migration:
double
,
get_all_versions:
existing_versions
)
}
let
(
:instrumentation
)
{
instance_double
(
Gitlab
::
Database
::
Migrations
::
Instrumentation
,
observations:
observations
)
}
let
(
:existing_versions
)
{
[
1
]
}
let
(
:all_migrations
)
{
[
double
(
'migration1'
,
version:
1
),
pending_migration
]
}
let
(
:pending_migration
)
{
double
(
'migration2'
,
version:
2
)
}
let
(
:filename
)
{
'results-file.json'
}
let
(
:buffer
)
{
StringIO
.
new
}
let
(
:filename
)
{
Gitlab
::
Database
::
Migrations
::
Instrumentation
::
STATS_FILENAME
}
let
!
(
:directory
)
{
Dir
.
mktmpdir
}
let
(
:observations
)
{
%w[some data]
}
before
do
...
...
@@ -316,17 +316,19 @@ RSpec.describe 'gitlab:db namespace rake task' do
allow
(
instrumentation
).
to
receive
(
:observe
).
and_yield
allow
(
File
).
to
receive
(
:open
).
with
(
filename
,
'wb+'
).
and_yield
(
buffer
)
allow
(
Dir
).
to
receive
(
:mkdir
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
directory
).
and_return
(
false
)
stub_const
(
'Gitlab::Database::Migrations::Instrumentation::RESULT_DIR'
,
directory
)
end
it
'fails when given no filename argument'
do
expect
{
run_rake_task
(
'gitlab:db:migration_testing'
)
}.
to
raise_error
(
/specify result_file/
)
after
do
FileUtils
.
rm_rf
([
directory
]
)
end
it
'fails when the
given file
already exists'
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
filename
).
and_return
(
true
)
it
'fails when the
directory
already exists'
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
directory
).
and_return
(
true
)
expect
{
subject
}.
to
raise_error
(
/
File
exists/
)
expect
{
subject
}.
to
raise_error
(
/
Directory
exists/
)
end
it
'instruments the pending migration'
do
...
...
@@ -344,7 +346,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
it
'writes observations out to JSON file'
do
subject
expect
(
buffer
.
string
).
to
eq
(
observations
.
to_json
)
expect
(
File
.
read
(
File
.
join
(
directory
,
filename
))
).
to
eq
(
observations
.
to_json
)
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