2018-05-21 16:41:21 +00:00
|
|
|
# rubocop:disable Style/SignalException
|
|
|
|
|
2018-07-10 10:10:54 +00:00
|
|
|
ANY_MIGRATIONS_REGEX = %r{\A(ee/)?(db/(geo/)?(post_)?migrate)/}
|
|
|
|
SCHEMA_NOT_UPDATED_MESSAGE = <<~MSG
|
|
|
|
**New %<migrations>s added but %<schema>s wasn't updated.**
|
|
|
|
|
|
|
|
Usually, when adding new %<migrations>s, %<schema>s should be
|
|
|
|
updated too (unless the migration isn't changing the DB schema
|
|
|
|
and isn't the most recent one).
|
|
|
|
MSG
|
|
|
|
|
|
|
|
non_geo_db_schema_updated = !git.modified_files.grep(%r{\Adb/schema\.rb/}).empty?
|
|
|
|
geo_db_schema_updated = !git.modified_files.grep(%r{\Aee/db/geo/schema\.rb/}).empty?
|
|
|
|
|
|
|
|
any_migration_created = !git.added_files.grep(ANY_MIGRATIONS_REGEX).empty?
|
|
|
|
any_migration_updated = !git.modified_files.grep(ANY_MIGRATIONS_REGEX).empty?
|
|
|
|
|
|
|
|
non_geo_migration_created = !git.added_files.grep(%r{\A(db/(post_)?migrate)/}).empty?
|
|
|
|
geo_migration_created = !git.added_files.grep(%r{\Aee/db/geo/(post_)?migrate/}).empty?
|
|
|
|
|
|
|
|
if any_migration_created || any_migration_updated || non_geo_db_schema_updated || geo_db_schema_updated
|
|
|
|
message "Please make sure to ask a Database engineer for a review."
|
|
|
|
end
|
|
|
|
|
|
|
|
if non_geo_migration_created && !non_geo_db_schema_updated
|
|
|
|
warn format(SCHEMA_NOT_UPDATED_MESSAGE, migrations: 'migrations', schema: gitlab.html_link("db/schema.rb"))
|
|
|
|
end
|
|
|
|
|
|
|
|
if geo_migration_created && !geo_db_schema_updated
|
|
|
|
warn format(SCHEMA_NOT_UPDATED_MESSAGE, migrations: 'Geo migrations', schema: gitlab.html_link("ee/db/geo/schema.rb"))
|
2018-05-21 16:41:21 +00:00
|
|
|
end
|