No commit activity in last 3 years
No release in over 3 years
manage snapshot materialized views for ActiveRecord. multiple versions of each view are maintained, a live version, a working version and 1 or more history versions, all created and managed automatically
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0.10.5
>= 0

Runtime

>= 2.3.9
 Project Readme

activerecord_snapshot_view¶ ↑

activerecord_snapshot_view provides simple management of snapshot materialized views for ActiveRecord

a snapshot view is created by includeing the ActiveRecord::SnapshotView module into an ActiveRecord class. new versions of the snapshot are created using the new_version class method

multiple versions of the view are maintained : there is a single active version, a working version, and one or more history tables [by default 1]

the model’s table_name method is overwritten to reflect the active table, so all ActiveRecord model methods, like finders, work transparently. the caveat is that you must use the table_name method to determine the current snapshot’s table name when constructing SQL

to use, include ActiveRecord::SnapshotView into your model :

class Foo < ActiveRecord::Base
  include ActiveRecord::SnapshotView
end

there are class methods to get the different table names, and manipulate the version :

  • Foo.table_name : current active or working table name

  • Foo.working_table_name : current working table name

  • Foo.active_table_name : current active table name

  • Foo.new_version(&block) : run block to create a new version of the table

  • Foo.updated_version(&block) : copy all data from the active table to the working table, then run block to update the working version

during the execution of block in new_version or updated_version Foo.table_name returns the working table name. if block completes without raising an exception, or if the exception is an ActiveRecord::SnapshotView::SaveWork, then the working table becomes permanently globally active

the active table name is maintained as a row in an automatically created auxilliary table, [foos_switch in the case of Foo], and this is updated in a transaction

the presence of the historical tables [which are recycled] means that even though a transaction may advance_version, other transactions already in progress will continue to see the old active table_name, and selects in progress will continue to completion without rollback [ provided they don’t take longer to complete than it takes to recycle all history tables ]

Dependencies¶ ↑

MySQL only at the moment

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 mccraig mccraig of the clan mccraig. See LICENSE for details.