Commit 013e8606 authored by pbair's avatar pbair

Remove use of rm_rf on dump of version files

Opt to use rm with a glob of filenames to clean out a directory over
using rm_rf to delete the entire directory
parent 9d700020
...@@ -8,16 +8,10 @@ module Gitlab ...@@ -8,16 +8,10 @@ module Gitlab
def dump_schema_information # :nodoc: def dump_schema_information # :nodoc:
versions = schema_migration.all_versions versions = schema_migration.all_versions
touch_version_files(versions) if versions.any? Gitlab::Database::SchemaVersionFiles.touch_all(versions) if versions.any?
nil nil
end end
private
def touch_version_files(versions)
Gitlab::Database::SchemaVersionFiles.touch_all(versions)
end
end end
end end
end end
......
...@@ -8,12 +8,6 @@ module Gitlab ...@@ -8,12 +8,6 @@ module Gitlab
def structure_load(*args) def structure_load(*args)
super(*args) super(*args)
load_version_files
end
private
def load_version_files
Gitlab::Database::SchemaVersionFiles.load_all Gitlab::Database::SchemaVersionFiles.load_all
end end
end end
......
...@@ -6,8 +6,8 @@ module Gitlab ...@@ -6,8 +6,8 @@ module Gitlab
SCHEMA_DIRECTORY = "db/schema_migrations" SCHEMA_DIRECTORY = "db/schema_migrations"
def self.touch_all(versions) def self.touch_all(versions)
FileUtils.rm_rf(schema_dirpath) filenames_with_path = find_version_filenames.map { |f| schema_dirpath.join(f) }
FileUtils.mkdir_p(schema_dirpath) FileUtils.rm(filenames_with_path)
versions.each do |version| versions.each do |version|
FileUtils.touch(schema_dirpath.join(version)) FileUtils.touch(schema_dirpath.join(version))
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Database::PostgresqlAdapter::DumpSchemaVersionsMixin do describe Gitlab::Database::PostgresqlAdapter::DumpSchemaVersionsMixin do
let(:schema_migration) { double('schem_migration', table_name: table_name, all_versions: versions) } let(:schema_migration) { double('schema_migration', all_versions: versions) }
let(:table_name) { "schema_migrations" }
let(:instance) do let(:instance) do
Object.new.extend(described_class) Object.new.extend(described_class)
......
...@@ -4,14 +4,14 @@ require 'spec_helper' ...@@ -4,14 +4,14 @@ require 'spec_helper'
describe Gitlab::Database::SchemaVersionFiles do describe Gitlab::Database::SchemaVersionFiles do
describe '.touch_all' do describe '.touch_all' do
let(:versions) { %w[123 456 890] } let(:versions) { %w[2020123 2020456 2020890] }
it 'touches a file for each version given' do it 'touches a file for each version given' do
Dir.mktmpdir do |tmpdir| Dir.mktmpdir do |tmpdir|
schema_dirpath = Pathname.new(tmpdir).join("test") schema_dirpath = Pathname.new(tmpdir).join("test")
FileUtils.mkdir_p(schema_dirpath) FileUtils.mkdir_p(schema_dirpath)
old_version_filepath = schema_dirpath.join("001") old_version_filepath = schema_dirpath.join("2020001")
FileUtils.touch(old_version_filepath) FileUtils.touch(old_version_filepath)
expect(File.exist?(old_version_filepath)).to be(true) expect(File.exist?(old_version_filepath)).to be(true)
......
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