Skip to content
[DEPRECATED - use mini_record] Declare a table structure like an ActiveRecord migration and run 'force_schema!' whenever you want. For when you don't need up and down migrations.



class Car < ActiveRecord::Base
  set_primary_key :name
  force_schema do
    string   'name'       # Nissan Altima, will automatically be indexed because it's the primary key
    string   'make_name'  # Nissan
    string   'model_name' # Altime
    float    'fuel_efficiency_city'
    string   'fuel_efficiency_city_units'
    float    'fuel_efficiency_highway'
    string   'fuel_efficiency_highway_units'
    integer  'year'
    datetime 'released_at'
    date     'released_on'
    index    ['name', 'make_name']

Warning: data loss

If you call Car.force_schema!, it may destroy data by adding, removing, or changing the type of columns. No attempt is made to preserve data.

What it synchronizes

  • adds missing columns

  • adds missing indexes

  • removes unrecognized columns

  • removes unrecognized indexes

  • changes the type of columns if it doesn't match what you asked for

  • changes the columns indexed if they don't match what you asked for

  • makes sure default value is synced up

Supported databases

  • MySQL is tested

  • SQLite is tested

  • Postgres is not supported


Extracted from In production use at and

Copyright 2011 Seamus Abshere

Something went wrong with that request. Please try again.