No commit activity in last 3 years
No release in over 3 years
extend active records with simple archiving mechanics
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0

Runtime

< 6.0, >= 4.2
 Project Readme

Activerecord Hoarder

Build Status Maintainability

hoard records

1 Use

1.0 configure

before performing 1.2 and 1.3 the ActiverecordHoarder::Storage needs to be configured with

  • storage: :aws_s3 - only storage currently implemented
  • storage_options: {...} with s3 credentials, connection details and default permissions

Amazon S3 options

  • access_key_id required - amazon credential
  • acl required - amazon canned ACL (private, public-read, ...)*
  • bucket required - amazon connection detail
  • bucket_sub_dir optional - amazon key prefix
  • region required - amazon connection detail
  • secret_access_key required - amazon credential

1.1 make model a hoarder

class ExampleModel < ActiveRecord::Base
  acts_as_hoarder
end

1.2 hoarding records

from console:

ExampleModel.hoard(options)

will create S3 entries with keys: <bucket_sub_dir>/<table_name = example_models>/<year>/<month>/<year>-<month>-<day>.json and json formatted content

To only archive a single batch of records do:

ExampleModel.hoard_single(options)

Options can be added to the options hash:

  • start_at_date
  • max_count

1.3 restoring records

from console:

ExampleModel.restore_archive_records(Date.new(<Y>,<m>,<d>))

2 Development

2.0 initial setup

Make a clone. Make a branch. Install dependencies.

2.1 playing around

Configure database

Create config file from template (cp config/dbspec.yml.template config/dbspec.yml). Change database from postgresql to sqlite3 and database name from activerecord_hoarder to <as_desired>.sqlite3.

Configure archive

Create config file from template (cp config/activerecord_hoarder.yml.template config/activerecord_hoarder.yml). Add your S3 credentials access_key_id and secret_access_key for target bucket bucket. Change region if necessary. If you want, change acl and add bucket_sub_dir.

Hop into sandbox

bundler exec bin/console

bin/example

Convenience functionality

  • require_relative "example/schema" for creating an example table examples
  • require_relative "example/example" for an example archivable model Example
  • require_relative "example/fixture" for a factory method create_examples(count, start: 0, deleted: true) for creating examples

2.2 testing it

Configure test database

Create config file from template (cp config/dbspec_rspec.yml.template config/dbspec_rspec.yml). Modify settings if you want.

Run tests

bundler exec rspec spec