diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /scripts/database | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'scripts/database')
-rw-r--r-- | scripts/database/schema_validator.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/database/schema_validator.rb b/scripts/database/schema_validator.rb new file mode 100644 index 00000000000..11a53faa945 --- /dev/null +++ b/scripts/database/schema_validator.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require_relative '../migration_schema_validator' + +class SchemaValidator < MigrationSchemaValidator + ALLOW_SCHEMA_CHANGES = 'ALLOW_SCHEMA_CHANGES' + COMMIT_MESSAGE_SKIP_TAG = 'skip-db-structure-check' + + def validate! + return if should_skip? + + return if schema_changes.empty? + + die "#{FILENAME} was changed, and no migrations were added:\n#{schema_changes}" if committed_migrations.empty? + end + + private + + def schema_changes + @schema_changes ||= run("git diff #{diff_target} HEAD -- #{FILENAME}") + end + + def should_skip? + skip_env_present? || skip_commit_present? + end + + def skip_env_present? + !ENV[ALLOW_SCHEMA_CHANGES].to_s.empty? + end + + def skip_commit_present? + run("git show -s --format=%B -n 1").to_s.include?(COMMIT_MESSAGE_SKIP_TAG) + end +end |