From c0fded4f92792a2c488d2f476747724f5378d049 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Mon, 27 Oct 2025 16:24:28 +1100 Subject: [PATCH] complete rename --- db/migrate/create_outboxer_counters.rb | 25 +++++++++++++++++++ db/migrate/create_outboxer_thread_counters.rb | 25 ------------------- lib/outboxer.rb | 2 +- .../models/{thread_counter.rb => counter.rb} | 4 +-- ...thread_counter_spec.rb => counter_spec.rb} | 22 ++++++++-------- tasks/database.rake | 4 +-- 6 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 db/migrate/create_outboxer_counters.rb delete mode 100644 db/migrate/create_outboxer_thread_counters.rb rename lib/outboxer/models/{thread_counter.rb => counter.rb} (96%) rename spec/lib/outboxer/models/{thread_counter_spec.rb => counter_spec.rb} (81%) diff --git a/db/migrate/create_outboxer_counters.rb b/db/migrate/create_outboxer_counters.rb new file mode 100644 index 00000000..37200725 --- /dev/null +++ b/db/migrate/create_outboxer_counters.rb @@ -0,0 +1,25 @@ +class CreateOutboxerCounters < ActiveRecord::Migration[6.1] + def up + create_table :outboxer_counters do |t| + t.string :hostname, limit: 255 + t.integer :process_id + t.integer :thread_id + + t.integer :publisher_id + + t.integer :queued_count, null: false + t.integer :publishing_count, null: false + t.integer :published_count, null: false + t.integer :failed_count, null: false + + t.timestamps + end + + add_index :outboxer_counters, [:hostname, :process_id, :thread_id], + unique: true, name: "idx_outboxer_counters_identity" + end + + def down + drop_table :outboxer_counters if table_exists?(:outboxer_counters) + end +end diff --git a/db/migrate/create_outboxer_thread_counters.rb b/db/migrate/create_outboxer_thread_counters.rb deleted file mode 100644 index 527f028b..00000000 --- a/db/migrate/create_outboxer_thread_counters.rb +++ /dev/null @@ -1,25 +0,0 @@ -class CreateOutboxerThreadCounters < ActiveRecord::Migration[6.1] - def up - create_table :outboxer_thread_counters do |t| - t.string :hostname, limit: 255, null: false - t.integer :process_id, null: false - t.integer :thread_id, null: false - - t.integer :publisher_id - - t.integer :queued_count, null: false - t.integer :publishing_count, null: false - t.integer :published_count, null: false - t.integer :failed_count, null: false - - t.timestamps - end - - add_index :outboxer_thread_counters, [:hostname, :process_id, :thread_id], - unique: true, name: "idx_outboxer_thread_counters_identity" - end - - def down - drop_table :outboxer_thread_counters if table_exists?(:outboxer_thread_counters) - end -end diff --git a/lib/outboxer.rb b/lib/outboxer.rb index 3d5bdeb0..48d14579 100644 --- a/lib/outboxer.rb +++ b/lib/outboxer.rb @@ -10,7 +10,7 @@ require_relative "outboxer/models/message" require_relative "outboxer/models/message_count" require_relative "outboxer/models/message_total" -require_relative "outboxer/models/thread_counter" +require_relative "outboxer/models/counter" require_relative "outboxer/models/publisher" require_relative "outboxer/models/signal" diff --git a/lib/outboxer/models/thread_counter.rb b/lib/outboxer/models/counter.rb similarity index 96% rename from lib/outboxer/models/thread_counter.rb rename to lib/outboxer/models/counter.rb index 834efc74..c32e0c39 100644 --- a/lib/outboxer/models/thread_counter.rb +++ b/lib/outboxer/models/counter.rb @@ -1,7 +1,7 @@ module Outboxer module Models - class ThreadCounter < ::ActiveRecord::Base - self.table_name = "outboxer_thread_counters" + class Counter < ::ActiveRecord::Base + self.table_name = "outboxer_counters" def self.insert_or_increment_by(hostname: Socket.gethostname, process_id: Process.pid, diff --git a/spec/lib/outboxer/models/thread_counter_spec.rb b/spec/lib/outboxer/models/counter_spec.rb similarity index 81% rename from spec/lib/outboxer/models/thread_counter_spec.rb rename to spec/lib/outboxer/models/counter_spec.rb index 427f4e8e..e3b99682 100644 --- a/spec/lib/outboxer/models/thread_counter_spec.rb +++ b/spec/lib/outboxer/models/counter_spec.rb @@ -2,7 +2,7 @@ module Outboxer module Models - RSpec.describe ThreadCounter, type: :model do + RSpec.describe Counter, type: :model do describe ".insert_or_increment_by" do let(:hostname) { "test-host" } let(:process_id) { 12_345 } @@ -11,16 +11,16 @@ module Models it "inserts a new row successfully" do expect do - ThreadCounter.insert_or_increment_by( + Counter.insert_or_increment_by( hostname: hostname, process_id: process_id, thread_id: thread_id, queued_count: 1, time: now ) - end.to change(ThreadCounter, :count).by(1) + end.to change(Counter, :count).by(1) - row = ThreadCounter.find_by( + row = Counter.find_by( hostname: hostname, process_id: process_id, thread_id: thread_id @@ -31,21 +31,21 @@ module Models end it "increments existing counts if called again" do - ThreadCounter.insert_or_increment_by( + Counter.insert_or_increment_by( hostname: hostname, process_id: process_id, thread_id: thread_id, queued_count: 1 ) - ThreadCounter.insert_or_increment_by( + Counter.insert_or_increment_by( hostname: hostname, process_id: process_id, thread_id: thread_id, queued_count: 2 ) - row = ThreadCounter.find_by( + row = Counter.find_by( hostname: hostname, process_id: process_id, thread_id: thread_id @@ -55,7 +55,7 @@ module Models end it "updates multiple counters atomically" do - ThreadCounter.insert_or_increment_by( + Counter.insert_or_increment_by( hostname: hostname, process_id: process_id, thread_id: thread_id, @@ -64,7 +64,7 @@ module Models failed_count: 3 ) - row = ThreadCounter.find_by( + row = Counter.find_by( hostname: hostname, process_id: process_id, thread_id: thread_id @@ -77,7 +77,7 @@ module Models it "does not create duplicate rows on repeated calls" do 3.times do - ThreadCounter.insert_or_increment_by( + Counter.insert_or_increment_by( hostname: hostname, process_id: process_id, thread_id: thread_id, @@ -85,7 +85,7 @@ module Models ) end - count = ThreadCounter.where( + count = Counter.where( hostname: hostname, process_id: process_id, thread_id: thread_id diff --git a/tasks/database.rake b/tasks/database.rake index f3e0b3c1..b23afac5 100644 --- a/tasks/database.rake +++ b/tasks/database.rake @@ -28,8 +28,8 @@ namespace :outboxer do db_config = Outboxer::Database.config(environment: environment, pool: 1) ActiveRecord::Base.establish_connection(db_config) - require_relative "../db/migrate/create_outboxer_thread_counters" - CreateOutboxerThreadCounters.new.up + require_relative "../db/migrate/create_outboxer_counters" + CreateOutboxerCounters.new.up require_relative "../db/migrate/create_outboxer_messages" CreateOutboxerMessages.new.up