Skip to content

Commit f993b36

Browse files
vincent-pochetD1353L
authored andcommitted
misc(clickhouse): Define primary key for events_enriched table (#5555)
## Description This PR sets the `primary_key` attribute for `events_enriched` and `events_enriched_expanded` tables. These two tables does not define a primary key and this change allows us to use `in_batch` AR method with a `cursor` to loop over rows.
1 parent fa7c2af commit f993b36

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

app/models/clickhouse/events_enriched.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Clickhouse
44
class EventsEnriched < BaseRecord
55
self.table_name = "events_enriched"
6+
self.primary_key = [:organization_id, :code, :external_subscription_id, :timestamp]
67
end
78
end
89

app/models/clickhouse/events_enriched_expanded.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
module Clickhouse
44
class EventsEnrichedExpanded < BaseRecord
55
self.table_name = "events_enriched_expanded"
6+
self.primary_key = [
7+
:organization_id,
8+
:code,
9+
:external_subscription_id,
10+
:charge_id,
11+
:charge_filter_id,
12+
:timestamp
13+
]
614
end
715
end
816

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Clickhouse::EventsEnrichedExpanded, clickhouse: true do
6+
subject(:events_enriched_expanded) { create(:clickhouse_events_enriched_expanded) }
7+
8+
it "persists a record via the factory" do
9+
expect(events_enriched_expanded).to be_persisted
10+
end
11+
12+
describe ".table_name" do
13+
it "is events_enriched_expanded" do
14+
expect(described_class.table_name).to eq("events_enriched_expanded")
15+
end
16+
end
17+
18+
describe ".primary_key" do
19+
it "matches the ClickHouse table primary key" do
20+
expect(described_class.primary_key).to eq(
21+
["organization_id", "code", "external_subscription_id", "charge_id", "charge_filter_id", "timestamp"]
22+
)
23+
end
24+
end
25+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Clickhouse::EventsEnriched, clickhouse: true do
6+
subject(:events_enriched) { create(:clickhouse_events_enriched) }
7+
8+
it "persists a record via the factory" do
9+
expect(events_enriched).to be_persisted
10+
end
11+
12+
describe ".table_name" do
13+
it "is events_enriched" do
14+
expect(described_class.table_name).to eq("events_enriched")
15+
end
16+
end
17+
18+
describe ".primary_key" do
19+
it "matches the ClickHouse table primary key" do
20+
expect(described_class.primary_key).to eq(
21+
["organization_id", "code", "external_subscription_id", "timestamp"]
22+
)
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)