Repository is archived
No commit activity in last 3 years
No release in over 3 years
Signalize when some primary key overflow soon.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 1.14
>= 0
>= 0
~> 10.0
~> 3.0

Runtime

>= 0
 Project Readme

ActiveRecord::OverflowSignalizer

Build Status

One day primary key field will overflow, but if you use this gem, you will know about it before it happens.

Installation

Add this line to your application's Gemfile:

gem 'activerecord-overflow_signalizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-overflow_signalizer

Usage

Just place it somewhere in your app:

ActiveRecord::OverflowSignalizer.new.analyse

By default it checks all models in your application and logs if some primary key will overflow soon or overflowed. Also you can use unsafe method #analyse!, so it will raise error.

You can place it in some job and perform it by clockwork or just run it when app starts in a separate thread.

Also you can pass some parameters to the initializer:

  • Specify logger
ActiveRecord::OverflowSignalizer.new(logger: SomeCoolLogger)

By default ActiveRecord::Base.logger

  • Specify list of models
ActiveRecord::OverflowSignalizer.new(models: [ModelName])

By default it retrieves all descendants of ActiveRecord::Base

  • Specify count of days. Gem starts to notify you if some primary key will overflow over the next number of days.
ActiveRecord::OverflowSignalizer.new(days_count: 360)

60 days by default

  • You can use your own signalizer for notification sending to e-mail, slack, hipchat, etc.
class MyAwesomeSignalizer
  def initialize(some_params)
    @notifier = SomeChatNotifier.new(some_params)
  end

  def signalize(msg)
    @notifier.send_msg(msg)
  end
end

ActiveRecord::OverflowSignalizer.new(signalizer: MyAwesomeSignalizer.new(some_params))

By default it uses only logging

Development

For tests you need a postgresql connection specified in spec/database.yml.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/funbox/activerecord-overflow_signalizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.