Gold Record

ActiveRecord extension for unobtrusive binary UUIDs
Alternatives To Gold Record
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Model_stubbing55
15 years agomitRuby
Replacement for ActiveRecord fixtures using an extremely flexible ruby-based approach.
Named_seeds44
97 years ago12December 22, 20161mitRuby
:id::seedling::seedling: Replace ActiveRecord Fixtures With #{YourFactories}
Activerecord_constraints26
11 years ago2May 19, 2012gpl-3.0Ruby
Create database constraints in Rails migrations and handle the exceptions they produce
Running_man2413111 years ago9March 07, 20132mitRuby
Activerecord Migrations13
3 years ago11June 07, 2020Ruby
A gem to simplify activerecord migrations in non-rails projects.
Iron_fixture_extractor12
15 years ago5August 05, 20132mitRuby
When object factories don't work because your data is too complex and creating manual fixtures is cumbersome and brittle: Iron Fixture Extractor (for ActiveRecord/Rails)
Transactional Factories12
13 years agomitRuby
Using nested-transactions to initialize test data programmatically.
Gold Record9
14 years agomitRuby
ActiveRecord extension for unobtrusive binary UUIDs
Mongoid Fixture_set8
77 years ago11June 23, 20165mitRuby
Fixtures for Mongoid
Ar_multi_threaded_transactional_tests7
13 years ago6December 27, 2020mitRuby
Execute multithreaded code while still using transactional fixtures by synchronizing db access to a single connection
Alternatives To Gold Record
Select To Compare


Alternative Project Comparisons
Readme

GoldRecord

Unobtrusive binary UUIDs for ActiveRecord.

DESCRIPTION

GoldRecord is an extension for ActiveRecord that implements unobtrusive binary UUIDs in MySQL.

FEATURES

GoldRecord supports SchemaDumper by not declaring the id column a PRIMARY KEY. The odds of a random UUID collision are documented here.

  • Uses space-efficient 16-byte binary representation for UUIDs.

  • Works with associations, migrations and ActiveRecord::SchemaDumper.

  • Transparently converts to hex-encoded UUIDs in #to_param.

  • Transparently handles binary, hex-encoded and URL-safe Base64 UUIDs in #find.

SYNOPSIS

class Blog < ActiveRecord::Base
  acts_as_gold_record
  has_many :posts
end

class Post < ActiveRecord::Base
  acts_as_gold_record
end

Or, for the exceptionally paranoid:

class LargeHadron < ActiveRecord::Base
  acts_as_gold_record
  set_primary_key :lottery_number
  validates_uniqueness_of :lottery_number, :on => :create
end

FIXTURES

# In test/helper.rb or spec_helper.rb:
require 'active_record/fixtures'
Fixtures.send :include, GoldRecord::Fixtures

MIGRATIONS

class MakeGoldRecords < ActiveRecord::Migration
  TABLES = [:labels, :record_stores]
  ASSOCIATIONS = [
    [:artists, :label_id, :id],
    [:labels_record_stores, :label_id, false],
    [:labels_record_stores, :record_store_id, false],
    [:artists_record_stores, :record_store_id, false],
  ]

  def self.up
    # Change each int(11) id column to binary(16).
    # This preserves the columns original value as a right-padded 16-byte string.
    TABLES.each do |table|
      change_integer_primary_key_to_uuid(table)
      add_index table, :id
    end

    # Change association columns to binary(16).
    ASSOCIATIONS.each do |table, column, primary_key|
      change_integer_to_uuid(table, column, primary_key)
    end
  end

  # Down migration designed to be run immediately after an up migration
  # in the event of some failure. Running this after generating any UUIDs
  # will produce unpredictable results.

  def self.down
    # Change each binary(16) id column to int(11).
    # MySQL casts the string value to an integer.
    TABLES.each do |table|
      remove_index table, :id
      change_uuid_to_integer_primary_key(table)
    end

    # Change association columns to int(11).
    ASSOCIATIONS.each do |table, column|
      change_uuid_to_integer(table, column, primary_key)
    end
  end
end

INSTALL

As a gem:

[sudo] gem install gold-record

As a Rails plugin:

Clone/copy to vendor/plugins/gold_record.

Popular Activerecord Projects
Popular Fixtures Projects
Popular Data Processing Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Ruby
Activerecord
Fixtures