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
0e39ae3f
Commit
0e39ae3f
authored
Jun 02, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove pending builds data migration
parent
4661cf85
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
143 deletions
+0
-143
db/post_migrate/20210520105029_copy_pending_builds_to_pending_builds_table.rb
...0520105029_copy_pending_builds_to_pending_builds_table.rb
+0
-55
db/schema_migrations/20210520105029
db/schema_migrations/20210520105029
+0
-1
spec/migrations/copy_pending_builds_to_pending_builds_table_spec.rb
...tions/copy_pending_builds_to_pending_builds_table_spec.rb
+0
-87
No files found.
db/post_migrate/20210520105029_copy_pending_builds_to_pending_builds_table.rb
deleted
100644 → 0
View file @
4661cf85
# frozen_string_literal: true
class
CopyPendingBuildsToPendingBuildsTable
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
BATCH_SIZE
=
10000
disable_ddl_transaction!
class
Build
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
scope
:pending
,
->
do
where
(
status:
'pending'
)
.
where
(
type:
'Ci::Build'
)
.
where
(
'updated_at > ?'
,
24
.
hours
.
ago
)
.
order
(
'id ASC'
)
end
end
def
up
Build
.
pending
.
limit
(
1
).
pluck
(
:id
).
first
.
try
do
|
id
|
Build
.
where
(
'id >= ?'
,
id
).
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
|
min_id
,
max_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<~
SQL
WITH pending_builds AS (
SELECT id,
project_id
FROM ci_builds
WHERE status = 'pending'
AND type = 'Ci::Build'
AND NOT EXISTS (
SELECT 1 FROM ci_pending_builds
WHERE ci_pending_builds.build_id = ci_builds.id
)
AND id BETWEEN
#{
min_id
}
AND
#{
max_id
}
)
INSERT INTO ci_pending_builds (build_id, project_id)
SELECT id,
project_id
FROM pending_builds
ON CONFLICT DO NOTHING
SQL
end
end
end
def
down
# noop
end
end
db/schema_migrations/20210520105029
deleted
100644 → 0
View file @
4661cf85
8eade0cf920391deb0ee1d6c7eee765b8ffc6e08c7c37ef34ef6062c9049609e
\ No newline at end of file
spec/migrations/copy_pending_builds_to_pending_builds_table_spec.rb
deleted
100644 → 0
View file @
4661cf85
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20210520105029_copy_pending_builds_to_pending_builds_table.rb'
)
RSpec
.
describe
CopyPendingBuildsToPendingBuildsTable
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:queue
)
{
table
(
:ci_pending_builds
)
}
let
(
:builds
)
{
table
(
:ci_builds
)
}
before
do
namespaces
.
create!
(
id:
123
,
name:
'sample'
,
path:
'sample'
)
projects
.
create!
(
id:
123
,
name:
'sample'
,
path:
'sample'
,
namespace_id:
123
)
builds
.
create!
(
id:
1
,
project_id:
123
,
status:
'pending'
,
type:
'Ci::Build'
,
created_at:
4
.
days
.
ago
,
updated_at:
4
.
days
.
ago
)
builds
.
create!
(
id:
2
,
project_id:
123
,
status:
'pending'
,
type:
'Ci::Build'
)
builds
.
create!
(
id:
3
,
project_id:
123
,
status:
'pending'
,
type:
'GenericCommitStatus'
)
builds
.
create!
(
id:
4
,
project_id:
123
,
status:
'pending'
,
type:
'GenericCommitStatus'
)
builds
.
create!
(
id:
5
,
project_id:
123
,
status:
'pending'
,
type:
'Ci::Bridge'
)
builds
.
create!
(
id:
6
,
project_id:
123
,
status:
'pending'
,
type:
'Ci::Build'
)
builds
.
create!
(
id:
7
,
project_id:
123
,
status:
'running'
,
type:
'Ci::Build'
)
builds
.
create!
(
id:
8
,
project_id:
123
,
status:
'created'
,
type:
'Ci::Build'
)
end
context
'when there are new pending builds present'
do
it
'migrates data'
do
migrate!
expect
(
queue
.
all
.
count
).
to
eq
2
expect
(
queue
.
all
.
pluck
(
:build_id
)).
to
match_array
([
2
,
6
])
end
end
context
'when there are pending builds already migrated present'
do
before
do
queue
.
create!
(
id:
1
,
build_id:
2
,
project_id:
123
)
end
it
'does not copy entries that have already been copied'
do
expect
(
queue
.
all
.
count
).
to
eq
1
migrate!
expect
(
queue
.
all
.
count
).
to
eq
2
expect
(
queue
.
all
.
pluck
(
:build_id
)).
to
match_array
([
2
,
6
])
end
end
context
'when there is more than one batch of pending builds to migrate'
do
before
do
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
end
it
'correctly migrates data and exits after doing that'
do
migrate!
expect
(
queue
.
all
.
count
).
to
eq
2
expect
(
queue
.
all
.
pluck
(
:build_id
)).
to
match_array
([
2
,
6
])
end
end
context
'when an old build has been recently updated'
do
before
do
builds
.
find
(
1
).
touch
end
it
'migrates it as well'
do
migrate!
expect
(
queue
.
all
.
count
).
to
eq
3
expect
(
queue
.
all
.
pluck
(
:build_id
)).
to
match_array
([
1
,
2
,
6
])
end
end
context
'when there is no data to migrate'
do
before
do
builds
.
all
.
delete_all
end
it
'does not raise an exception'
do
expect
(
builds
.
all
.
count
).
to
eq
0
expect
{
migrate!
}.
not_to
raise_error
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