2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
class MigrateNullWikiAccessLevels < ActiveRecord::Migration[4.2]
|
2018-11-20 20:47:30 +05:30
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
class ProjectFeature < ActiveRecord::Base
|
|
|
|
include EachBatch
|
|
|
|
|
|
|
|
self.table_name = 'project_features'
|
|
|
|
end
|
|
|
|
|
|
|
|
def up
|
|
|
|
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
|
|
|
|
# there is no way to rollback this change, there are no downsides in keeping migrated data.
|
|
|
|
end
|
|
|
|
end
|