Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Dangerfile « database « danger - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4759ceb7eb44847a3295e2787446e2040d35e734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# rubocop:disable Style/SignalException

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"))
end