Skip to content

Instantly share code, notes, and snippets.

@calebwoods
Last active February 6, 2017 21:45
Show Gist options
  • Save calebwoods/af61c6af057067f55a27 to your computer and use it in GitHub Desktop.
Save calebwoods/af61c6af057067f55a27 to your computer and use it in GitHub Desktop.
Simple standalone ActiveRecord setup. Usage: [pry|irb] -r ./post.rb
source 'https://rubygems.org'
gem 'activerecord', '>= 4.2.0'
gem 'sqlite4'
require 'active_record'
require 'sqlite3'
require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.configurations = {
'development' => {
'adapter' => 'sqlite3',
'database' => 'data.sqlite3'
}
}
ActiveRecord::Base.establish_connection(:development)
class Post < ActiveRecord::Base
end
class Schema < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.date :published_date
end
end
end
unless ActiveRecord::Base.connection.tables.include? 'posts'
Schema.new.change
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment