Skip to content

Instantly share code, notes, and snippets.

@SafeAF
Forked from npassaro/gist:307a23f40287482a5275
Created October 31, 2015 09:51
Show Gist options
  • Save SafeAF/7d1f4eecdc06ca591d86 to your computer and use it in GitHub Desktop.
Save SafeAF/7d1f4eecdc06ca591d86 to your computer and use it in GitHub Desktop.
How to use activerecord standalone
require 'active_record'
require 'sqlite3'
require 'logger'
ActiveRecord::Base.logger = Logger.new('debug.log')
ActiveRecord::Base.configurations = YAML::load(IO.read('database.yml'))
ActiveRecord::Base.establish_connection('development')
class Schema < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :state
end
add_index :users, :name
end
end
Schema.new.change
class User < ActiveRecord::Base
end
######################
# database.yml:
######################
development:
adapter: sqlite3
database: db/data.sqlite3
pool: 5
timeout: 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment