summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-05-08 00:14:00 +0000
committerStan Hu <stanhu@gmail.com>2018-05-08 00:14:00 +0000
commitcb7a6d343a75497312b35739272cf994a0bc5e7b (patch)
tree3c4cce15d0cd5ce5bb89bd60e6317c71d93956d0 /app
parent9a2d09e3a9ae16f62cba317d8064d9409c95321a (diff)
parent18094a17458aab8c9d629b86946b61e0e7bab251 (diff)
downloadgitlab-ce-cb7a6d343a75497312b35739272cf994a0bc5e7b.tar.gz
Merge branch '5794-we-should-failover-gracefully-when-we-can-t-connect-to-geo-tracking-database-ce' into 'master'
Backport: Keep ShaAttribute from halting startup when we can’t connect to a database See merge request gitlab-org/gitlab-ce!18726
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/sha_attribute.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/app/models/concerns/sha_attribute.rb b/app/models/concerns/sha_attribute.rb
index 703a72c355c..3340dc96e9f 100644
--- a/app/models/concerns/sha_attribute.rb
+++ b/app/models/concerns/sha_attribute.rb
@@ -4,18 +4,33 @@ module ShaAttribute
module ClassMethods
def sha_attribute(name)
return if ENV['STATIC_VERIFICATION']
- return unless table_exists?
+
+ validate_binary_column_exists!(name) unless Rails.env.production?
+
+ attribute(name, Gitlab::Database::ShaAttribute.new)
+ end
+
+ # This only gets executed in non-production environments as an additional check to ensure
+ # the column is the correct type. In production it should behave like any other attribute.
+ # See https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/5502 for more discussion
+ def validate_binary_column_exists!(name)
+ unless table_exists?
+ warn "WARNING: sha_attribute #{name.inspect} is invalid since the table doesn't exist - you may need to run database migrations"
+ return
+ end
column = columns.find { |c| c.name == name.to_s }
- # In case the table doesn't exist we won't be able to find the column,
- # thus we will only check the type if the column is present.
- if column && column.type != :binary
- raise ArgumentError,
- "sha_attribute #{name.inspect} is invalid since the column type is not :binary"
+ unless column
+ raise ArgumentError.new("sha_attribute #{name.inspect} is invalid since the column doesn't exist")
end
- attribute(name, Gitlab::Database::ShaAttribute.new)
+ unless column.type == :binary
+ raise ArgumentError.new("sha_attribute #{name.inspect} is invalid since the column type is not :binary")
+ end
+ rescue => error
+ Gitlab::AppLogger.error "ShaAttribute initialization: #{error.message}"
+ raise
end
end
end