Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

activerecord_worm_table

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activerecord_worm_table

  • 0.8.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= activerecord_worm_table

activerecord_worm_table manages multiple backing tables for an ActiveRecord model. there is a single active table, a different working table, and one or more history tables [default 1]

inserts are done to the working table. the model's class method advance_version then makes the the active table history, the working table active, and creates a new working table with identical schema to the base table

the model's +table_name+ method is overwritten to reflect the active table, so all ActiveRecord model methods, like finders, work transparently

to use, just include ActiveRecord::WormTable into your model :

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

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

  • Foo.table_name : current active table name
  • Foo.advance_version(&block) : run +block+ to create a new version of the table. the working table will appear active to the +Thread+ running +block+ , and if +block+ completes then the working table will become permanently globally active
  • Foo.working_table_name : current working table name
  • Foo.advance_version : make active table historical, working table active and create a new working table

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

only works with MySQL at the moment : ddl statements are too database specific, and rails' schema operations too limited, to easily make it generic. wouldn't be too hard to extend for another db tho

== 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

Copyright (c) 2009 mccraig mccraig of the clan mccraig. See LICENSE for details.

FAQs

Package last updated on 11 Mar 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc