Project

monogamy

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Add table-level database locking to ActiveRecord
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Monogamy (archived)

Adds table-level locking to ActiveRecord 4.2 and 5.0. MySQL and PostgreSQL are supported.

Build Status Gem Version Dependency Status

Usage

Tag.with_table_lock do
  Tag.where(name: "example").first_or_create
end

While your code is inside the block, it will have exclusive read and write access to the model's table.

A transaction will be opened and closed for you automatically during your block's execution. There's no need to wrap your call to with_table_lock with a transaction do.

If your block touches other tables, and you use table-level locking on those tables as well, read up about deadlocks. You have been warned.

Installation

Add this line to your application's Gemfile:

gem 'monogamy'

And then execute:

$ bundle

Changelog

0.0.1

  • First whack