Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

mceachen/monogamy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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