Last active
December 19, 2015 15:09
-
-
Save npassaro/307a23f40287482a5275 to your computer and use it in GitHub Desktop.
How to use activerecord standalone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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