Rename Geo::PushEvent to Geo::RepositoryUpdatedEvent

parent 5f28791b
......@@ -2,6 +2,7 @@ module Geo
class EventLog < ActiveRecord::Base
include Geo::Model
belongs_to :push_event, class_name: 'Geo::PushEvent', foreign_key: 'push_event_id'
belongs_to :repository_updated_event, class_name: 'Geo::RepositoryUpdatedEvent',
foreign_key: 'repository_updated_event_id'
end
end
module Geo
class PushEvent < ActiveRecord::Base
class RepositoryUpdatedEvent < ActiveRecord::Base
include Geo::Model
REPOSITORY = 0
......
module Geo
class PushEventStore
class RepositoryUpdatedEventStore
attr_reader :project, :source, :refs, :changes
def initialize(project, refs: [], changes: [], source: Geo::PushEvent::REPOSITORY)
def initialize(project, refs: [], changes: [], source: Geo::RepositoryUpdatedEvent::REPOSITORY)
@project = project
@refs = refs
@changes = changes
......@@ -14,7 +14,7 @@ module Geo
Geo::EventLog.transaction do
event_log = Geo::EventLog.new
event_log.push_event = build_push_event
event_log.repository_updated_event = build_event
event_log.save!
end
rescue ActiveRecord::RecordInvalid
......@@ -23,8 +23,8 @@ module Geo
private
def build_push_event
Geo::PushEvent.new(
def build_event
Geo::RepositoryUpdatedEvent.new(
project: project,
source: source,
ref: ref,
......
......@@ -13,7 +13,7 @@ module EE
super
# Generate repository updated event on Geo event log when Geo is enabled
::Geo::PushEventStore.new(post_received.project, refs: refs, changes: changes).create
::Geo::RepositoryUpdatedEventStore.new(post_received.project, refs: refs, changes: changes).create
end
def process_wiki_changes(post_received)
......@@ -23,7 +23,7 @@ module EE
if ::Gitlab::Geo.enabled?
# Create wiki repository updated event on Geo event log
::Geo::PushEventStore.new(post_received.project, source: Geo::PushEvent::WIKI).create
::Geo::RepositoryUpdatedEventStore.new(post_received.project, source: Geo::RepositoryUpdatedEvent::WIKI).create
# Triggers repository update on secondary nodes
::Gitlab::Geo.notify_wiki_update(post_received.project)
......
class CreateGeoPushEvents < ActiveRecord::Migration
class CreateGeoRepositoryUpdatedEvents < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :geo_push_events, id: :bigserial do |t|
create_table :geo_repository_updated_events, id: :bigserial do |t|
t.datetime :created_at, null: false
t.integer :branches_affected, null: false
t.integer :tags_affected, null: false
......
......@@ -4,9 +4,10 @@ class CreateGeoEventLog < ActiveRecord::Migration
def change
create_table :geo_event_log, id: :bigserial do |t|
t.datetime :created_at, index: true, null: false
t.integer :push_event_id, limit: 8, index: true
t.integer :repository_updated_event_id, limit: 8, index: true
t.foreign_key :geo_push_events, column: :push_event_id, on_delete: :cascade
t.foreign_key :geo_repository_updated_events,
column: :repository_updated_event_id, on_delete: :cascade
end
end
end
......@@ -502,11 +502,11 @@ ActiveRecord::Schema.define(version: 20170602003304) do
create_table "geo_event_log", id: :bigserial, force: :cascade do |t|
t.datetime "created_at", null: false
t.integer "push_event_id", limit: 8
t.integer "repository_updated_event_id", limit: 8
end
add_index "geo_event_log", ["created_at"], name: "index_geo_event_log_on_created_at", using: :btree
add_index "geo_event_log", ["push_event_id"], name: "index_geo_event_log_on_push_event_id", using: :btree
add_index "geo_event_log", ["repository_updated_event_id"], name: "index_geo_event_log_on_repository_updated_event_id", using: :btree
create_table "geo_nodes", force: :cascade do |t|
t.string "schema"
......@@ -528,7 +528,7 @@ ActiveRecord::Schema.define(version: 20170602003304) do
add_index "geo_nodes", ["host"], name: "index_geo_nodes_on_host", using: :btree
add_index "geo_nodes", ["primary"], name: "index_geo_nodes_on_primary", using: :btree
create_table "geo_push_events", id: :bigserial, force: :cascade do |t|
create_table "geo_repository_updated_events", id: :bigserial, force: :cascade do |t|
t.datetime "created_at", null: false
t.integer "branches_affected", null: false
t.integer "tags_affected", null: false
......@@ -539,8 +539,8 @@ ActiveRecord::Schema.define(version: 20170602003304) do
t.text "ref"
end
add_index "geo_push_events", ["project_id"], name: "index_geo_push_events_on_project_id", using: :btree
add_index "geo_push_events", ["source"], name: "index_geo_push_events_on_source", using: :btree
add_index "geo_repository_updated_events", ["project_id"], name: "index_geo_repository_updated_events_on_project_id", using: :btree
add_index "geo_repository_updated_events", ["source"], name: "index_geo_repository_updated_events_on_source", using: :btree
create_table "historical_data", force: :cascade do |t|
t.date "date", null: false
......@@ -1688,8 +1688,8 @@ ActiveRecord::Schema.define(version: 20170602003304) do
add_foreign_key "ci_triggers", "users", column: "owner_id", name: "fk_e8e10d1964", on_delete: :cascade
add_foreign_key "ci_variables", "projects", name: "fk_ada5eb64b3", on_delete: :cascade
add_foreign_key "container_repositories", "projects"
add_foreign_key "geo_event_log", "geo_push_events", column: "push_event_id", on_delete: :cascade
add_foreign_key "geo_push_events", "projects", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_repository_updated_events", column: "repository_updated_event_id", on_delete: :cascade
add_foreign_key "geo_repository_updated_events", "projects", on_delete: :cascade
add_foreign_key "issue_assignees", "issues", name: "fk_b7d881734a", on_delete: :cascade
add_foreign_key "issue_assignees", "users", name: "fk_5e0c8d9154", on_delete: :cascade
add_foreign_key "issue_metrics", "issues", on_delete: :cascade
......
......@@ -2,6 +2,6 @@ require 'rails_helper'
RSpec.describe Geo::EventLog, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:push_event).class_name('Geo::PushEvent').with_foreign_key('push_event_id') }
it { is_expected.to belong_to(:repository_updated_event).class_name('Geo::RepositoryUpdatedEvent').with_foreign_key('repository_updated_event_id') }
end
end
require 'rails_helper'
RSpec.describe Geo::PushEvent, type: :model do
RSpec.describe Geo::RepositoryUpdatedEvent, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
end
......
require 'spec_helper'
describe Geo::PushEventStore, services: true do
describe Geo::RepositoryUpdatedEventStore, services: true do
let(:project) { create(:project) }
let(:blankrev) { Gitlab::Git::BLANK_SHA }
let(:refs) { ['refs/heads/tést', 'refs/tags/tag'] }
......@@ -18,7 +18,7 @@ describe Geo::PushEventStore, services: true do
subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.create }.not_to change(Geo::PushEvent, :count)
expect { subject.create }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
context 'when running on a primary node' do
......@@ -29,7 +29,7 @@ describe Geo::PushEventStore, services: true do
it 'creates a push event' do
subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.create }.to change(Geo::PushEvent, :count).by(1)
expect { subject.create }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end
context 'when repository is being updated' do
......@@ -38,7 +38,7 @@ describe Geo::PushEventStore, services: true do
subject.create
expect(Geo::PushEvent.last.ref).to be_nil
expect(Geo::RepositoryUpdatedEvent.last.ref).to be_nil
end
it 'tracks ref name when post-receive event affect single ref' do
......@@ -48,7 +48,7 @@ describe Geo::PushEventStore, services: true do
subject.create
expect(Geo::PushEvent.last.ref).to eq 'refs/heads/tést'
expect(Geo::RepositoryUpdatedEvent.last.ref).to eq 'refs/heads/tést'
end
it 'tracks number of branches post-receive event affects' do
......@@ -56,7 +56,7 @@ describe Geo::PushEventStore, services: true do
subject.create
expect(Geo::PushEvent.last.branches_affected).to eq 1
expect(Geo::RepositoryUpdatedEvent.last.branches_affected).to eq 1
end
it 'tracks number of tags post-receive event affects' do
......@@ -64,7 +64,7 @@ describe Geo::PushEventStore, services: true do
subject.create
expect(Geo::PushEvent.last.tags_affected).to eq 1
expect(Geo::RepositoryUpdatedEvent.last.tags_affected).to eq 1
end
it 'tracks when post-receive event create new branches' do
......@@ -78,7 +78,7 @@ describe Geo::PushEventStore, services: true do
subject.create
expect(Geo::PushEvent.last.new_branch).to eq true
expect(Geo::RepositoryUpdatedEvent.last.new_branch).to eq true
end
it 'tracks when post-receive event remove branches' do
......@@ -91,17 +91,17 @@ describe Geo::PushEventStore, services: true do
subject.create
expect(Geo::PushEvent.last.remove_branch).to eq true
expect(Geo::RepositoryUpdatedEvent.last.remove_branch).to eq true
end
end
context 'when wiki is being updated' do
it 'does not track any information' do
subject = described_class.new(project, source: Geo::PushEvent::WIKI)
subject = described_class.new(project, source: Geo::RepositoryUpdatedEvent::WIKI)
subject.create
push_event = Geo::PushEvent.last
push_event = Geo::RepositoryUpdatedEvent.last
expect(push_event.ref).to be_nil
expect(push_event.branches_affected).to be_zero
......
......@@ -25,8 +25,8 @@ describe PostReceive do
allow_any_instance_of(GitPushService).to receive(:execute).and_return(true)
end
it 'calls Geo::PushEventStore' do
expect_any_instance_of(Geo::PushEventStore).to receive(:create)
it 'calls Geo::RepositoryUpdatedEventStore' do
expect_any_instance_of(Geo::RepositoryUpdatedEventStore).to receive(:create)
described_class.new.perform(project_identifier, key_id, base64_changes)
end
......@@ -36,11 +36,11 @@ describe PostReceive do
describe '#process_wiki_changes' do
let(:project_identifier) { "#{pwd(project)}.wiki" }
it 'triggers Geo::PushEventStore when Geo is enabled' do
it 'triggers Geo::RepositoryUpdatedEventStore when Geo is enabled' do
allow(Gitlab::Geo).to receive(:enabled?) { true }
expect(Geo::PushEventStore).to receive(:new).with(instance_of(Project), source: Geo::PushEvent::WIKI).and_call_original
expect_any_instance_of(Geo::PushEventStore).to receive(:create)
expect(Geo::RepositoryUpdatedEventStore).to receive(:new).with(instance_of(Project), source: Geo::RepositoryUpdatedEvent::WIKI).and_call_original
expect_any_instance_of(Geo::RepositoryUpdatedEventStore).to receive(:create)
described_class.new.perform(project_identifier, key_id, base64_changes)
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