diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-05-22 10:58:31 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-05-22 10:58:53 +0200 |
commit | b5918f222b603058c0773f067f7925e026932992 (patch) | |
tree | 31cc265f57c1620e741da5e235f33f252cd5fa13 /db | |
parent | 6233e56e99b63e2fe1787753967833245ff932aa (diff) | |
download | gitlab-ce-b5918f222b603058c0773f067f7925e026932992.tar.gz |
Fixes broken MySQL migration for retried
> Mysql2::Error: Table 'ci_builds' is specified twice, both as a target for 'UPDATE' and as a separate source for data: UPDATE `ci_builds` SET `retried` = ((SELECT MAX(ci_builds2.id)
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/32647
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170503004427_upate_retried_for_ci_build.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb b/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb index 9b20edeb4c3..738e46b9207 100644 --- a/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb +++ b/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb @@ -8,6 +8,32 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration def up disable_statement_timeout + if Gitlab::Database.mysql? + up_mysql + else + up_postgres + end + end + + def down + end + + private + + def up_mysql + # This is a trick to overcome MySQL limitation: + # Mysql2::Error: Table 'ci_builds' is specified twice, both as a target for 'UPDATE' and as a separate source for data + # However, this leads to create a temporary table from `max(ci_builds.id)` which is slow and do full database update + execute <<-SQL.strip_heredoc + UPDATE ci_builds SET retried= + (id NOT IN ( + SELECT * FROM (SELECT MAX(ci_builds.id) FROM ci_builds GROUP BY commit_id, name) AS latest_jobs + )) + WHERE retried IS NULL + SQL + end + + def up_postgres with_temporary_partial_index do latest_id = <<-SQL.strip_heredoc SELECT MAX(ci_builds2.id) @@ -26,9 +52,6 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration end end - def down - end - def with_temporary_partial_index if Gitlab::Database.postgresql? execute 'CREATE INDEX CONCURRENTLY IF NOT EXISTS index_for_ci_builds_retried_migration ON ci_builds (id) WHERE retried IS NULL;' |