Commit 0148b328 authored by pbair's avatar pbair

Write version hashes to schema version files

When creating a new schema version file, write the hash of the version
to the file to prevent git rename detection from confusing it with
another schema version file.
parent fe9dbbed
...@@ -10,7 +10,11 @@ module Gitlab ...@@ -10,7 +10,11 @@ module Gitlab
FileUtils.rm(filenames_with_path) FileUtils.rm(filenames_with_path)
versions.each do |version| versions.each do |version|
FileUtils.touch(schema_dirpath.join(version)) version_filepath = schema_dirpath.join(version)
File.open(version_filepath, 'w') do |file|
file << Digest::SHA256.hexdigest(version)
end
end end
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Database::PostgresqlAdapter::DumpSchemaVersionsMixin do RSpec.describe Gitlab::Database::PostgresqlAdapter::DumpSchemaVersionsMixin do
let(:schema_migration) { double('schema_migration', all_versions: versions) } let(:schema_migration) { double('schema_migration', all_versions: versions) }
let(:instance) do let(:instance) do
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Database::SchemaVersionFiles do RSpec.describe Gitlab::Database::SchemaVersionFiles do
describe '.touch_all' do describe '.touch_all' do
let(:versions) { %w[2020123 2020456 2020890] } let(:versions) { %w[2020123 2020456 2020890] }
it 'touches a file for each version given' do it 'creates a file containing a checksum 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)
...@@ -24,6 +24,9 @@ describe Gitlab::Database::SchemaVersionFiles do ...@@ -24,6 +24,9 @@ describe Gitlab::Database::SchemaVersionFiles do
versions.each do |version| versions.each do |version|
version_filepath = schema_dirpath.join(version) version_filepath = schema_dirpath.join(version)
expect(File.exist?(version_filepath)).to be(true) expect(File.exist?(version_filepath)).to be(true)
hashed_value = Digest::SHA256.hexdigest(version)
expect(File.read(version_filepath)).to eq(hashed_value)
end end
end end
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