diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-25 21:15:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-25 21:15:16 +0300 |
commit | 62866a623e24242c6f7a1a93dc2aca1467d6a6ae (patch) | |
tree | 322ce00c652d376c949f1d45c39764eeb5bce620 /scripts | |
parent | f8888a274f6b095075fd8648d3732ad577a3a742 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/regenerate-schema | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/regenerate-schema b/scripts/regenerate-schema index f1018403395..697177c0c0f 100755 --- a/scripts/regenerate-schema +++ b/scripts/regenerate-schema @@ -2,6 +2,7 @@ # frozen_string_literal: true +require 'optparse' require 'open3' require 'fileutils' require 'uri' @@ -27,6 +28,10 @@ class SchemaRegenerator # directory when it runs. SCHEMA_MIGRATIONS_DIR = 'db/schema_migrations/' + def initialize(options) + @rollback_testing = options.delete(:rollback_testing) + end + def execute Dir.chdir(File.expand_path('..', __dir__)) do checkout_ref @@ -37,6 +42,7 @@ class SchemaRegenerator reset_db unhide_migrations migrate + rollback if @rollback_testing ensure unhide_migrations end @@ -168,6 +174,15 @@ class SchemaRegenerator end ## + # Run rake task to rollback migrations. + def rollback + (untracked_schema_migrations + committed_schema_migrations).sort.reverse_each do |filename| + version = filename[/\d+\Z/] + run %(bin/rails db:rollback:main db:rollback:ci RAILS_ENV=test VERSION=#{version}) + end + end + + ## # Run the given +cmd+. # # The command is colored green, and the output of the command is @@ -224,4 +239,19 @@ class SchemaRegenerator end end -SchemaRegenerator.new.execute +if $PROGRAM_NAME == __FILE__ + options = {} + + OptionParser.new do |opts| + opts.on("-r", "--rollback-testing", String, "Enable rollback testing") do + options[:rollback_testing] = true + end + + opts.on("-h", "--help", "Prints this help") do + puts opts + exit + end + end.parse! + + SchemaRegenerator.new(options).execute +end |