diff --git a/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb b/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb index d3557efecbd..0a0a33299e4 100644 --- a/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb +++ b/db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb @@ -5,6 +5,8 @@ class MigrateNullWikiAccessLevels < ActiveRecord::Migration DOWNTIME = false + disable_ddl_transaction! + class ProjectFeature < ActiveRecord::Base include EachBatch @@ -15,6 +17,13 @@ class MigrateNullWikiAccessLevels < ActiveRecord::Migration ProjectFeature.where(wiki_access_level: nil).each_batch do |relation| relation.update_all(wiki_access_level: 20) end + + # We need to re-count wikis as previous attempt was not considering the NULLs. + transaction do + execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql? # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967 + + execute("UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)") + end end def down