diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 03:07:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 03:07:41 +0300 |
commit | 42263d6451c0af3c0e7a61747ffb046a806e4477 (patch) | |
tree | 989941de7bbf543963942e7d9a4b1b89bdf7e386 /lib/gitlab/database | |
parent | 2412ddf03da787012161ea1e8a03787275f9cde9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index f75e943671b..82a84508959 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -215,7 +215,7 @@ module Gitlab fk_name = name || concurrent_foreign_key_name(source, column) unless foreign_key_exists?(source, name: fk_name) - raise "cannot find #{fk_name} on #{source} table" + raise missing_schema_object_message(source, "foreign key", fk_name) end disable_statement_timeout do @@ -931,7 +931,10 @@ module Gitlab def column_for(table, name) name = name.to_s - columns(table).find { |column| column.name == name } + column = columns(table).find { |column| column.name == name } + raise(missing_schema_object_message(table, "column", name)) if column.nil? + + column end # This will replace the first occurrence of a string in a column with @@ -1166,6 +1169,18 @@ into similar problems in the future (e.g. when new tables are created). private + def missing_schema_object_message(table, type, name) + <<~MESSAGE + Could not find #{type} "#{name}" on table "#{table}" which was referenced during the migration. + This issue could be caused by the database schema straying from the expected state. + + To resolve this issue, please verify: + 1. all previous migrations have completed + 2. the database objects used in this migration match the Rails definition in schema.rb or structure.sql + + MESSAGE + end + def tables_match?(target_table, foreign_key_table) target_table.blank? || foreign_key_table == target_table end |