Skip to content
Snippets Groups Projects
Commit dac12de5 authored by Aakriti Gupta's avatar Aakriti Gupta :red_circle:
Browse files

# This is a combination of 2 commits.

# This is the 1st commit message:

Add vulnerability export replication

- add a registry table and replicator

# The commit message #2 will be skipped:

# Add changelog
parent f9f7cbaa
No related branches found
No related tags found
No related merge requests found
# frozen_string_literal: true
class CreateVulnerabilityExportRegistry < ActiveRecord::Migration[6.0]
DOWNTIME = false
disable_ddl_transaction!
def up
unless table_exists?(:vulnerability_export_registry)
ActiveRecord::Base.transaction do
create_table :vulnerability_export_registry, id: :bigserial, force: :cascade do |t|
t.integer :vulnerability_export_id, null: false
t.integer :state, default: 0, null: false, limit: 2
t.integer :retry_count, default: 0, limit: 2
t.text :last_sync_failure
t.datetime_with_timezone :retry_at
t.datetime_with_timezone :last_synced_at
t.datetime_with_timezone :created_at, null: false
t.index :vulnerability_export_id
t.index :retry_at
t.index :state
end
end
end
add_text_limit :vulnerability_export_registry, :last_sync_failure, 255
end
def down
drop_table :vulnerability_export_registry
end
end
# frozen_string_literal: true
class Geo::VulnerabilityExportRegistry < Geo::BaseRegistry
include Geo::ReplicableRegistry
MODEL_CLASS = ::Vulnerabilities::Export
MODEL_FOREIGN_KEY = :vulnerability_export_id
belongs_to :vulnerability_export, class_name: 'Vulnerabilities::Export'
# def has_create_events? needed?
end
# frozen_string_literal: true
module Geo
class VulnerabilityExportReplicator < Gitlab::Geo::Replicator
include ::Geo::BlobReplicatorStrategy
def self.model
::Vulnerabilities::Export
end
def carrierwave_uploader
model_record.file
end
end
end
---
title: 'Geo: Add vulnerability export replication'
merge_request: 36620
author:
type: added
# frozen_string_literal: true
FactoryBot.define do
factory :geo_vulnerability_export_registry, class: 'Geo::VulnerabilityExportRegistry' do
widget
state { Geo::VulnerabilityExportRegistry.state_value(:pending) }
trait :synced do
state { Geo::VulnerabilityExportRegistry.state_value(:synced) }
last_synced_at { 5.days.ago }
end
trait :failed do
state { Geo::VulnerabilityExportRegistry.state_value(:failed) }
last_synced_at { 1.day.ago }
retry_count { 2 }
last_sync_failure { 'Random error' }
end
trait :started do
state { Geo::VulnerabilityExportRegistry.state_value(:started) }
last_synced_at { 1.day.ago }
retry_count { 0 }
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::VulnerabilityExportRegistry, :geo, type: :model do
let_it_be(:registry) { create(:geo_vulnerability_export_registry) }
specify 'factory is valid' do
expect(registry).to be_valid
end
include_examples 'a Geo framework registry'
describe '.find_registry_differences' do
pending
# To be implemented
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::VulnerabilityExportReplicator do
let(:model_record) { build(:vulnerability_export) }
it_behaves_like 'a blob replicator'
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment