Commit 9bfbb92f authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ban_far_future_migration_timestamps' into 'master'

Prevent future timestamps in migration filenames

See merge request gitlab-org/gitlab!61473
parents 386d2245 9137b716
......@@ -341,6 +341,7 @@ db:check-schema:
- .rails:rules:ee-mr-and-default-branch-only
script:
- source scripts/schema_changed.sh
- scripts/validate_migration_timestamps
db:check-migrations:
extends:
......
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'time'
MIGRATION_DIRS = %w[db/migrate db/post_migrate].freeze
VERSION_DIGITS = 14
MIGRATION_TIMESTAMP_REGEX = /\A(?<version>\d{#{VERSION_DIGITS}})_/.freeze
maximum_timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S').to_i
MIGRATION_DIRS.each do |migration_dir|
Dir[File.join(migration_dir, '*.rb')].each do |filename|
file_basename = File.basename(filename)
version_match = MIGRATION_TIMESTAMP_REGEX.match(file_basename)
raise "#{filename} has an invalid migration version" if version_match.nil?
migration_timestamp = version_match['version'].to_i
raise "#{filename} has a future timestamp" if migration_timestamp > maximum_timestamp
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