Commit 85e83813 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Add WikiAccessLevel migration from `NULL` to `20`

parent fd9377fa
# frozen_string_literal: true
class MigrateNullWikiAccessLevels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
class ProjectFeature < ActiveRecord::Base
include EachBatch
self.table_name = 'project_features'
def up
ProjectFeature.where(wiki_access_level: nil).each_batch do |relation|
relation.update_all(wiki_access_level: 20)
def down
# there is no way to rollback this change, there are no downsides in keeping migrated data.
......@@ -11,7 +11,7 @@
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180808162000) do
ActiveRecord::Schema.define(version: 20180809195358) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20180809195358_migrate_null_wiki_access_levels.rb')
describe MigrateNullWikiAccessLevels, :migration do
let(:namespaces) { table('namespaces') }
let(:projects) { table(:projects) }
let(:project_features) { table(:project_features) }
let(:migration) { }
before do
namespace = namespaces.create(name: 'foo', path: 'foo')
projects.create!(id: 1, name: 'gitlab1', path: 'gitlab1', namespace_id:
projects.create!(id: 2, name: 'gitlab2', path: 'gitlab2', namespace_id:
projects.create!(id: 3, name: 'gitlab3', path: 'gitlab3', namespace_id:
project_features.create!(id: 1, project_id: 1, wiki_access_level: nil)
project_features.create!(id: 2, project_id: 2, wiki_access_level: 10)
project_features.create!(id: 3, project_id: 3, wiki_access_level: 20)
describe '#up' do
it 'migrates existing project_features with wiki_access_level NULL to 20' do
expect { migration.up }.to change { project_features.where(wiki_access_level: 20).count }.by(1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment