Commit 310fc401 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'tc-drop-ignored-geo-columns' into 'master'

Drop ignored Geo repository_storage_path columns

See merge request gitlab-org/gitlab-ee!5468
parents 9e8c7f45 d9ac0760
......@@ -1063,7 +1063,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table "geo_hashed_storage_migrated_events", id: :bigserial, force: :cascade do |t|
t.integer "project_id", null: false
t.text "repository_storage_name", null: false
t.text "repository_storage_path"
t.text "old_disk_path", null: false
t.text "new_disk_path", null: false
t.text "old_wiki_disk_path", null: false
......@@ -1175,7 +1174,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table "geo_repository_created_events", id: :bigserial, force: :cascade do |t|
t.integer "project_id", null: false
t.text "repository_storage_name", null: false
t.text "repository_storage_path"
t.text "repo_path", null: false
t.text "wiki_path"
t.text "project_name", null: false
......@@ -1186,7 +1184,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table "geo_repository_deleted_events", id: :bigserial, force: :cascade do |t|
t.integer "project_id", null: false
t.text "repository_storage_name", null: false
t.text "repository_storage_path"
t.text "deleted_path", null: false
t.text "deleted_wiki_path"
t.text "deleted_project_name", null: false
......@@ -1197,7 +1194,6 @@ ActiveRecord::Schema.define(version: 20180608201435) do
create_table "geo_repository_renamed_events", id: :bigserial, force: :cascade do |t|
t.integer "project_id", null: false
t.text "repository_storage_name", null: false
t.text "repository_storage_path"
t.text "old_path_with_namespace", null: false
t.text "new_path_with_namespace", null: false
t.text "old_wiki_path_with_namespace", null: false
......
module Geo
class HashedStorageMigratedEvent < ActiveRecord::Base
include Geo::Model
include IgnorableColumn
ignore_column :repository_storage_path
belongs_to :project
......
module Geo
class RepositoryCreatedEvent < ActiveRecord::Base
include Geo::Model
include IgnorableColumn
ignore_column :repository_storage_path
belongs_to :project
......
module Geo
class RepositoryDeletedEvent < ActiveRecord::Base
include Geo::Model
include IgnorableColumn
ignore_column :repository_storage_path
belongs_to :project
......
module Geo
class RepositoryRenamedEvent < ActiveRecord::Base
include Geo::Model
include IgnorableColumn
ignore_column :repository_storage_path
belongs_to :project
......
---
title: Drop ignored Geo repository_storage_path columns
merge_request: 5468
author:
type: removed
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class DropRepositoryStorageEventsForGeoEvents < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
TABLES = %i(geo_hashed_storage_migrated_events geo_repository_created_events
geo_repository_deleted_events geo_repository_renamed_events)
def up
transaction do
TABLES.each { |t| remove_column(t, :repository_storage_path) }
end
end
def down
TABLES.each do |t|
add_column(t, :repository_storage_path, :text)
update_repository_storage_path(t)
change_column_null(t, :repository_storage_path, true)
end
end
private
def update_repository_storage_path(table)
update_column_in_batches(table, :repository_storage_path, update_statement) do |t, q|
q.where(t[:repository_storage_path].eq(nil))
end
end
def update_statement
Arel.sql(
<<~SQL
CASE repository_storage_name
#{case_statements}
END
SQL
)
end
def case_statements
@case_statements ||= Gitlab.config.repositories.storages.map do |shard, data|
"WHEN '#{shard}' THEN '#{data.legacy_disk_path}'"
end.join("\n")
end
end
# encoding: utf-8
require 'spec_helper'
require Rails.root.join('ee', 'db', 'post_migrate', '20180417102933_drop_repository_storage_events_for_geo_events.rb')
describe DropRepositoryStorageEventsForGeoEvents, :migration do
describe '#up' do
before do
schema_migrate_up!
end
where(table_name: described_class::TABLES)
with_them do
it 'dropped the repository_storage_path column' do
columns = table(table_name).columns.map(&:name)
expect(columns).not_to include("repository_storage_path")
end
end
end
describe '#down' do
let(:namespace) { table(:namespaces).create!(name: 'foo', path: 'foo_namespace') }
let(:project) { table(:projects).create!(name: 'bar', path: 'path/to/bar', namespace_id: namespace.id) }
shared_examples 'recreates the repository_storage_path column' do
before do
schema_migrate_up!
Gitlab.config.repositories.storages.each do |name, _|
table(table_name).create!({ project_id: project.id, repository_storage_name: name }.merge(extra_cols))
end
schema_migrate_down!
end
it 'creates repository_storage_path column' do
columns = table(table_name).columns.map(&:name)
expect(columns).to include("repository_storage_path")
end
it 'fills in all repository_storage_path cells' do
null_columns = described_class
.exec_query("SELECT COUNT(*) as count FROM #{table_name} WHERE repository_storage_path IS NULL;")
.first['count']
expect(null_columns.to_i).to eq(0)
end
it 'fills in repository_storage_path with the legacy_disk_path' do
described_class.exec_query("SELECT repository_storage_name, repository_storage_path FROM #{table_name};").each do |row|
expect(row['repository_storage_path']).to eq(legacy_disk_path(row['repository_storage_name']))
end
end
end
context 'geo_hashed_storage_migrated_events' do
let(:table_name) { :geo_hashed_storage_migrated_events }
let(:extra_cols) do
{
old_disk_path: '/ye/olde/path', new_disk_path: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
old_wiki_disk_path: '/ye/olde/path.wiki', new_wiki_disk_path: 'da39a3ee5e6b4b0d3255bfef95601890afd80709.wiki',
new_storage_version: 2
}
end
it_behaves_like 'recreates the repository_storage_path column'
end
context 'geo_repository_created_events' do
let(:table_name) { :geo_repository_created_events }
let(:extra_cols) { { project_name: project.name, repo_path: project.path } }
it_behaves_like 'recreates the repository_storage_path column'
end
context 'geo_repository_deleted_events' do
let(:table_name) { :geo_repository_deleted_events }
let(:extra_cols) { { deleted_path: '/null/path', deleted_project_name: 'im_gone' } }
it_behaves_like 'recreates the repository_storage_path column'
end
context 'geo_repository_renamed_events' do
let(:table_name) { :geo_repository_renamed_events }
let(:extra_cols) do
{
old_path: '/ye/olde/path', new_path: '/ze/n3w/p4th',
old_path_with_namespace: '/ye/olde/namespace/path', new_path_with_namespace: '/ze/n3w/n4mesp4ce/p4th',
old_wiki_path_with_namespace: '/ye/olde/namespace/path.wiki', new_wiki_path_with_namespace: '/ze/n3w/n4mesp4ce/p4th.wiki'
}
end
it_behaves_like 'recreates the repository_storage_path column'
end
end
def legacy_disk_path(name)
Gitlab.config.repositories.storages[name].legacy_disk_path
end
end
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