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
13f5f7e6
Commit
13f5f7e6
authored
Jan 02, 2019
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration to cleanup iid records
parent
4ac06d34
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
db/post_migrate/20190102152410_delete_inconsistent_internal_id_records2.rb
...0190102152410_delete_inconsistent_internal_id_records2.rb
+43
-0
No files found.
db/post_migrate/20190102152410_delete_inconsistent_internal_id_records2.rb
0 → 100644
View file @
13f5f7e6
# frozen_string_literal: true
class
DeleteInconsistentInternalIdRecords2
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
# This migration cleans up any inconsistent records in internal_ids.
#
# That is, it deletes records that track a `last_value` that is
# smaller than the maximum internal id (usually `iid`) found in
# the corresponding model records.
def
up
disable_statement_timeout
do
delete_internal_id_records
(
'milestones'
,
'project_id'
)
delete_internal_id_records
(
'milestones'
,
'namespace_id'
,
'group_id'
)
end
end
class
InternalId
<
ActiveRecord
::
Base
self
.
table_name
=
'internal_ids'
enum
usage:
{
issues:
0
,
merge_requests:
1
,
deployments:
2
,
milestones:
3
,
epics:
4
,
ci_pipelines:
5
}
end
private
def
delete_internal_id_records
(
base_table
,
scope_column_name
,
base_scope_column_name
=
scope_column_name
)
sql
=
<<~
SQL
SELECT id FROM ( -- workaround for MySQL
SELECT internal_ids.id FROM (
SELECT
#{
base_scope_column_name
}
AS
#{
scope_column_name
}
, max(iid) as maximum_iid from
#{
base_table
}
GROUP BY
#{
scope_column_name
}
) maxima JOIN internal_ids USING (
#{
scope_column_name
}
)
WHERE internal_ids.usage=
#{
InternalId
.
usages
.
fetch
(
base_table
)
}
AND maxima.maximum_iid > internal_ids.last_value
) internal_ids
SQL
InternalId
.
where
(
"id IN (
#{
sql
}
)"
).
tap
do
|
ids
|
# rubocop:disable GitlabSecurity/SqlInjection
say
"Deleting internal_id records for
#{
base_table
}
:
#{
ids
.
map
{
|
i
|
[
i
.
project_id
,
i
.
last_value
]
}
}"
unless
ids
.
empty?
end
.
delete_all
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