diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /scripts/regenerate-schema | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'scripts/regenerate-schema')
-rwxr-xr-x | scripts/regenerate-schema | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/regenerate-schema b/scripts/regenerate-schema index cedd612f766..e2d46d14218 100755 --- a/scripts/regenerate-schema +++ b/scripts/regenerate-schema @@ -3,6 +3,7 @@ # frozen_string_literal: true require 'open3' +require 'fileutils' require 'uri' class SchemaRegenerator @@ -19,11 +20,19 @@ class SchemaRegenerator # these to disable/enable migrations. MIGRATION_DIRS = %w[db/migrate db/post_migrate].freeze + ## + # Directory where we store schema versions + # + # The remove_schema_migration_files removes files added in this + # directory when it runs. + SCHEMA_MIGRATIONS_DIR = 'db/schema_migrations/' + def execute Dir.chdir(File.expand_path('..', __dir__)) do checkout_ref checkout_clean_schema hide_migrations + remove_schema_migration_files reset_db unhide_migrations migrate @@ -111,6 +120,35 @@ class SchemaRegenerator end ## + # Remove files added to db/schema_migrations + # + # In order to properly reset the database and re-run migrations + # the schema migrations for new migrations must be removed. + def remove_schema_migration_files + (untracked_schema_migrations + commited_schema_migrations).each do |schema_migration| + FileUtils.rm(schema_migration) + end + end + + ## + # List of untracked schema migrations + # + # Get a list of schema migrations that are not tracked so we can remove them + def untracked_schema_migrations + git_command = "git ls-files --others --exclude-standard -- #{SCHEMA_MIGRATIONS_DIR}" + run(git_command).chomp.split("\n") + end + + ## + # List of untracked schema migrations + # + # Get a list of schema migrations that have been committed since the last + def commited_schema_migrations + git_command = "git diff --name-only --diff-filter=A #{merge_base} -- #{SCHEMA_MIGRATIONS_DIR}" + run(git_command).chomp.split("\n") + end + + ## # Run rake task to reset the database. def reset_db run %q[bin/rails db:reset RAILS_ENV=test] |