Commit b3dfc1da authored by Toon Claes's avatar Toon Claes Committed by Stan Hu

Changes cause success has a non-NULL constraint

`success` column cannot be NULL, so we need to adapt the code to
define what "never" synced means.
parent 9536d26e
...@@ -5,7 +5,8 @@ class Geo::FileRegistry < Geo::BaseRegistry ...@@ -5,7 +5,8 @@ class Geo::FileRegistry < Geo::BaseRegistry
scope :lfs_objects, -> { where(file_type: :lfs) } scope :lfs_objects, -> { where(file_type: :lfs) }
scope :attachments, -> { where(file_type: Geo::FileService::DEFAULT_OBJECT_TYPES) } scope :attachments, -> { where(file_type: Geo::FileService::DEFAULT_OBJECT_TYPES) }
scope :never, -> { where(retry_count: nil) } scope :failed, -> { where(success: false).where.not(retry_count: nil) }
scope :never, -> { where(success: false, retry_count: nil) }
scope :fresh, -> { order(created_at: :desc) } scope :fresh, -> { order(created_at: :desc) }
self.inheritance_column = 'file_type' self.inheritance_column = 'file_type'
...@@ -20,14 +21,10 @@ class Geo::FileRegistry < Geo::BaseRegistry ...@@ -20,14 +21,10 @@ class Geo::FileRegistry < Geo::BaseRegistry
def self.with_status(status) def self.with_status(status)
case status case status
when 'synced' when 'synced', 'never', 'failed'
synced self.public_send(status) # rubocop: disable GitlabSecurity/PublicSend
when 'never'
never
when 'failed'
failed
else else
self all
end end
end end
...@@ -36,10 +33,10 @@ class Geo::FileRegistry < Geo::BaseRegistry ...@@ -36,10 +33,10 @@ class Geo::FileRegistry < Geo::BaseRegistry
# It takes into account things like if a successful replication has been done # It takes into account things like if a successful replication has been done
# if there are pending actions or existing errors # if there are pending actions or existing errors
# #
# @return [Symbol] :never, :failed:, :pending or :synced # @return [Symbol] :synced, :never, or :failed
def synchronization_state def synchronization_state
return :synced if success? return :synced if success?
return :never if success.nil? && retry_count.nil? return :never if retry_count.nil?
:failed :failed
end end
......
require 'spec_helper' require 'spec_helper'
describe Geo::FileRegistry do describe Geo::FileRegistry do
set(:failed) { create(:geo_file_registry, success: false) } set(:failed) { create(:geo_file_registry, :failed) }
set(:synced) { create(:geo_file_registry, success: true) } set(:synced) { create(:geo_file_registry) }
describe '.failed' do describe '.failed' do
it 'returns registries in the failed state' do it 'returns registries in the failed state' do
...@@ -27,10 +27,9 @@ describe Geo::FileRegistry do ...@@ -27,10 +27,9 @@ describe Geo::FileRegistry do
describe '.never' do describe '.never' do
it 'returns registries that are never synced' do it 'returns registries that are never synced' do
create(:geo_file_registry, retry_count: 1, success: true) never = create(:geo_file_registry, retry_count: nil, success: false)
create(:geo_file_registry, retry_count: 2, success: false)
expect(described_class.never).to match_ids([failed, synced]) expect(described_class.never).to match_ids([never])
end end
end end
...@@ -59,7 +58,7 @@ describe Geo::FileRegistry do ...@@ -59,7 +58,7 @@ describe Geo::FileRegistry do
end end
it 'returns :never for a successful registry never synced' do it 'returns :never for a successful registry never synced' do
never = build(:geo_file_registry, success: nil) never = build(:geo_file_registry, success: false, retry_count: nil)
expect(never.synchronization_state).to eq(:never) expect(never.synchronization_state).to eq(:never)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment