Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.

Commit 582cdc7

Browse files
author
v.promzelev
committed
fixup error with unsupported types of pk
1 parent 5ddb047 commit 582cdc7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/activerecord/overflow_signalizer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def analyse!
2929
pk = model.columns.select { |c| c.name == model.primary_key }.first
3030
max = MAX_VALUE.fetch(pk.sql_type) do |type|
3131
@logger.warn "Model #{model} has primary_key #{model.primary_key} with unsupported type #{type}"
32+
nil
3233
end
34+
next unless max
3335
if overflow_soon?(max, model)
3436
overflowed_tables << [table, model.last.public_send(pk.name), max]
3537
end

spec/activerecord/overflow_signalizer_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@
1919
it { expect { subject.analyse! }.not_to raise_error }
2020
end
2121

22+
context 'unsupported type of primary key' do
23+
let(:today) { Time.now }
24+
let(:logger) { Logger.new('/dev/null') }
25+
before do
26+
(1..7).each do |t|
27+
record = TestStringModel.new(created_at: today - day * t, updated_at: today - day * t)
28+
record.id = "id#{t}"
29+
record.save!
30+
end
31+
end
32+
33+
subject { described_class.new(models: [TestStringModel], days_count: 10, logger: logger) }
34+
35+
it { expect { subject.analyse! }.not_to raise_error }
36+
end
37+
2238
context 'not empty table' do
2339
let(:today) { Time.now }
2440

spec/spec_helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'bundler/setup'
22
require 'activerecord/overflow_signalizer'
33
require 'byebug'
4+
require 'logger'
45
require 'active_record'
56

67
RSpec.configure do |config|
@@ -35,3 +36,15 @@ class TestBigIntModel < ActiveRecord::Base
3536
end
3637
TestBigIntModel.connection.execute(%Q{ ALTER TABLE "bigint_test" ADD PRIMARY KEY ("id"); })
3738
TestBigIntModel.reset_column_information
39+
40+
class TestStringModel < ActiveRecord::Base
41+
establish_connection YAML.load_file(DATABASE_CONFIG_PATH)
42+
self.table_name = 'string_test'
43+
end
44+
45+
TestBigIntModel.connection.create_table(:string_test, id: false, force: true) do |t|
46+
t.column :id, :string, null: false
47+
t.timestamps
48+
end
49+
TestBigIntModel.connection.execute(%Q{ ALTER TABLE "string_test" ADD PRIMARY KEY ("id"); })
50+
TestBigIntModel.reset_column_information

0 commit comments

Comments
 (0)