Skip to content

Commit

Permalink
feat: добавит enum тип в список возможных полей
Browse files Browse the repository at this point in the history
  • Loading branch information
folklore committed Jul 20, 2016
1 parent 047743c commit caa913e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ group :development, :test do
gem 'combustion', github: 'pat/combustion', ref: '7d0d24c3f36ce0eb336177fc493be0721bc26665'
end

gem 'rack', '< 2' if RUBY_VERSION < '2.2.0'

gemspec
6 changes: 5 additions & 1 deletion lib/redis_counters/dumpers/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ def columns_definition
when :boolean
'boolean'
else
raise 'Unknown datatype %s for %s field' % [type, field]
if type.is_a?(Array) && type.first == :enum
type.last.fetch(:name)
else
raise 'Unknown datatype %s for %s field' % [type, field]
end
end

"#{field} #{pg_field_type}"
Expand Down
1 change: 0 additions & 1 deletion redis_counters-dumpers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
spec.add_dependency 'callbacks_rb', '>= 0.0.1'
spec.add_dependency 'redis_counters', '>= 1.3'


spec.add_development_dependency 'bundler', '>= 1.7'
spec.add_development_dependency 'rake', '>= 10.0'
spec.add_development_dependency 'rspec', '>= 3.2'
Expand Down
7 changes: 7 additions & 0 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
ActiveRecord::Schema.define do
execute <<-SQL
CREATE TYPE subject_types AS ENUM ('');
SQL

create_table :stats_by_days do |t|
t.integer :record_id, null: false
t.integer :column_id, null: false
t.date :date, null: false
t.integer :hits, null: false, default: 0
t.column :subject, :subject_types
end

add_index :stats_by_days, [:record_id, :column_id, :date], unique: true
Expand All @@ -12,13 +17,15 @@
t.integer :record_id, null: false
t.integer :column_id, null: false
t.integer :hits, null: false, default: 0
t.column :subject, :subject_types
end

add_index :stats_totals, [:record_id, :column_id], unique: true

create_table :stats_agg_totals do |t|
t.integer :record_id, null: false
t.integer :hits, null: false, default: 0
t.column :subject, :subject_types
end

add_index :stats_agg_totals, [:record_id], unique: true
Expand Down
21 changes: 11 additions & 10 deletions spec/lib/redis_counters/dumpers/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
fields record_id: :integer,
column_id: :integer,
value: :integer,
date: :date
date: :date,
subject: [:enum, {name: :subject_types}]

destination do
model StatsByDay
Expand Down Expand Up @@ -51,7 +52,7 @@
RedisCounters.create_counter(Redis.current,
counter_class: RedisCounters::HashCounter,
counter_name: :record_hits_by_day,
group_keys: [:record_id, :column_id],
group_keys: [:record_id, :column_id, :subject],
partition_keys: [:date]
)
end
Expand All @@ -62,17 +63,17 @@

describe '#process!' do
before do
counter.increment(date: prev_date_s, record_id: 1, column_id: 100)
counter.increment(date: prev_date_s, record_id: 1, column_id: 200)
counter.increment(date: prev_date_s, record_id: 1, column_id: 200)
counter.increment(date: prev_date_s, record_id: 2, column_id: 100)
counter.increment(date: prev_date_s, record_id: 1, column_id: 100, subject: '')
counter.increment(date: prev_date_s, record_id: 1, column_id: 200, subject: '')
counter.increment(date: prev_date_s, record_id: 1, column_id: 200, subject: '')
counter.increment(date: prev_date_s, record_id: 2, column_id: 100, subject: nil)

dumper.process!(counter, prev_date)

counter.increment(date: date_s, record_id: 1, column_id: 100)
counter.increment(date: date_s, record_id: 1, column_id: 200)
counter.increment(date: date_s, record_id: 1, column_id: 200)
counter.increment(date: date_s, record_id: 2, column_id: 100)
counter.increment(date: date_s, record_id: 1, column_id: 100, subject: '')
counter.increment(date: date_s, record_id: 1, column_id: 200, subject: '')
counter.increment(date: date_s, record_id: 1, column_id: 200, subject: '')
counter.increment(date: date_s, record_id: 2, column_id: 100, subject: nil)

dumper.process!(counter, date)
end
Expand Down

0 comments on commit caa913e

Please sign in to comment.