Commit graph

27 commits

Author SHA1 Message Date
James Lopez
f8acc7ea77 fixing spec failures 2016-11-17 08:22:55 +01:00
James Lopez
1a4ff5d720 Added code events spec and logic. Also fixed SQL issues and refactored the code a bit. 2016-11-17 08:22:55 +01:00
James Lopez
470e39d64f WIP - refactored some arel queries 2016-11-17 08:22:54 +01:00
Timothy Andrew
244ec0a84c Implement fourth round of comments from @DouweM.
- Pluralize summary titles
- Remove the `run_query` method - always return sql strings from the
  `date_time_sql` methods
2016-09-21 09:57:14 +05:30
Timothy Andrew
6df2d57394 Improve indentation in Gitlab::Database::Median 2016-09-21 02:18:57 +05:30
Timothy Andrew
918e589c2b Implement a second round of review comments from @DouweM.
- Don't use `TableReferences` - using `.arel_table` is shorter!
- Move some database-related code to `Gitlab::Database`
- Remove the `MergeRequest#issues_closed` and
  `Issue#closed_by_merge_requests`  associations. They were either
  shadowing or were too similar to existing methods. They are not being
  used anywhere, so it's better to remove them to reduce confusion.
- Use Rails 3-style validations
- Index for `MergeRequest::Metrics#first_deployed_to_production_at`
- Only include `CycleAnalyticsHelpers::TestGeneration` for specs that
  need it.
- Other minor refactorings.
2016-09-21 00:47:37 +05:30
Timothy Andrew
231a9f5b87 Fix rubocop spec.
And `scss_lint`
2016-09-20 18:26:31 +05:30
Timothy Andrew
71d4bf721b Implement (some) comments from @DouweM's review.
- Move things common to `Issue` and `MergeRequest` into `Issuable`
- Move more database-specific functions into `Gitlab::Database`
- Indentation changes and other minor refactorings.
2016-09-20 18:13:11 +05:30
Timothy Andrew
8957293d9b Implement review comments from @yorickpeterse
1. Change multiple updates to a single `update_all`

2. Use cascading deletes

3. Extract an average function for the database median.

4. Move database median to `lib/gitlab/database`

5. Use `delete_all` instead of `destroy_all`

6. Minor refactoring
2016-09-20 16:05:25 +05:30
Drew Blessing
e000f02bd3 Add support for column limits in add_column_with_default 2016-09-15 21:59:58 -05:00
Stan Hu
f700f3ec5d Disable statement timeout outside of transaction and during adding concurrent index 2016-07-14 18:50:46 -07:00
Stan Hu
e5c7e11840 Disable PostgreSQL statement timeout during migrations
Long-running migrations may take more than the timeout allowed by
the database. Disable the session's statement timeout to ensure
migrations don't get killed prematurely.
2016-07-14 18:40:54 -07:00
Yorick Peterse
c1e756c242
Fix update_column_in_batches to update all rows
This changes update_column_in_batches to ensure it always updates all
rows now. These changes also allow for an extra SELECT query to be
removed, nor does it use the row count for determining offsets and the
likes; instead it's only used to determine the batch size.
2016-06-17 17:50:38 +02:00
Yorick Peterse
816c453558
Don't update columns in batches in a transaction
This ensures that whatever locks are acquired aren't held onto until the
end of the transaction (= after _all_ rows have been updated). Timing
wise there's also no difference between using a transaction and not
using one.
2016-06-15 17:04:07 +02:00
Yorick Peterse
8966263e0c
Customizing of update_column_in_batches queries
By passing a block to update_column_in_batches() one can now customize
the queries executed. This in turn can be used to only update a specific
set of rows instead of simply all the rows in the table.
2016-06-15 16:44:44 +02:00
Yorick Peterse
ea7ff13410
Removed old comment from update_column_in_batches 2016-06-13 11:50:27 +02:00
Yorick Peterse
9c238dc970
Update columns in batches until no rows are left
Instead of updating a fixed number of rows (based on the amount of rows
available at the start of the update) the method
"update_column_in_batches" will now continue updating rows until it runs
out of rows to process.

For a table with a high rate of inserts this may result in the migration
taking quite some time. However, the alternative is not all rows being
updated or the "change_column_null" method raising an error due to there
being NULL values.
2016-06-13 11:38:57 +02:00
Yorick Peterse
b33b7be53e
Handle NULL migration errors in migration helpers
This ensures that whenever changing the NULL constraint of a column
fails we still drop the column.
2016-06-13 11:22:58 +02:00
Felipe Artur
9264203103 change add_concurrent_index function arguments 2016-06-06 13:06:21 -03:00
Felipe Artur
8450fe3074 Add index to notification settings 2016-06-03 16:46:10 -03:00
Grzegorz Bizon
7f9092da1e Extend comment for migrations helper MySQL fix 2016-05-22 23:31:33 +02:00
Grzegorz Bizon
2df8b48dbb Add MySQL compatibility fix in migration helpers 2016-05-22 22:44:59 +02:00
Yorick Peterse
c22be75794
Removed outdated comment from migration helpers 2016-05-19 12:36:02 -05:00
Yorick Peterse
59640866ce
Remove left-over use of strip_heredoc 2016-05-19 10:04:46 -05:00
Yorick Peterse
6a29117793
Removed stray strip_heredoc from migration helpers 2016-05-13 00:11:01 +02:00
Yorick Peterse
36083b4d0e
Fixed styling per Rubocop pedantics 2016-05-12 13:03:55 +02:00
Yorick Peterse
e867099091
Added helper methods for database migrations
These helpers can be used to perform migrations without taking down the
entire application.

For example, the method "add_column_with_default" can be used to add a
new column with a default value without locking the entire table.
2016-05-12 12:59:40 +02:00