Commit Graph

7 Commits

Author SHA1 Message Date
Yorick Peterse b3331cf3df
Added Rubocop config for background migrations
This adds a Rubocop configuration file specific to
lib/gitlab/background_migrations. This configuration will be used to
(hopefully) make reviewing background migrations easier by enforcing
stricter rules compared to the rest of GitLab. Because this
configuration is directory specific it will only affect background
migrations.
2017-11-23 13:56:51 +01:00
Sean McGivern 9245bfc293 Handle null serialised commits in background migration
This is already handled for diffs, but not commits.
2017-10-17 12:15:40 +01:00
Sean McGivern 1507ff8ab7 Make MR diff background migration less likely to time out
This version does not use transactions, but individual statements. As we have
unique constraints on the target tables for the inserts, we can just ignore
uniqueness violations there (as long as we always insert the same batch size, in
the same order).

This means the spec now must use truncation, not a transaction, as the
uniqueness violation means that the whole transaction for that spec would be
invalid, which isn't what we'd want. In real-world use, this isn't run in a
transaction anyway.

This commit also wraps unhandled exceptions, for easier finding in Sentry, and
logs with a consistent format, for easier searching.
2017-09-29 11:56:08 +01:00
Sean McGivern 917194153f Insert at most 1,000 rows at once in MR diff background migration
We were hitting the statement timeout for very large MR diffs. Now we insert at
most 1,000 rows to `merge_request_diff_commits` in a single statement, or 100
rows to `merge_request_diff_files`.
2017-09-29 11:00:19 +01:00
Sean McGivern 34a859ee2a Fix MR diffs background migration when file modes are missing
Guess the modes based on the following:

1. If the file didn't exist, it's zero.
2. If the diff contains 'Subproject commit', it might be a submodule, so 0600.
3. Otherwise, it's 0644.

This isn't perfect, but it doesn't have to be - it won't change file modes in
the repository.
2017-08-18 13:02:30 +01:00
Sean McGivern d2315054e6 Fix merge request diff deserialisation when too_large was absent
Not all diffs in st_diffs had the too_large attribute set at all, but the column
is non-nullable. Explicitly cast to boolean to avoid that problem.
2017-08-11 11:58:36 +01:00
Sean McGivern f2d50af917 Migrate MR commits and diffs to new tables
Previously, we stored these as serialised fields - `st_{commits,diffs}` - on the
`merge_request_diffs` table. These now have their own tables -
`merge_request_diff_{commits,diffs}` - with a column for each attribute of the
serialised data.

Add a background migration to go through the existing MR diffs and migrate them
to the new format. Ignore any contents that cannot be displayed. Assuming that
we have 5 million rows to migrate, and each batch of 2,500 rows can be
completed in 5 minutes, this will take about 7 days to migrate everything.
2017-08-03 13:20:26 +01:00