Instantly share code, notes, and snippets.

Embed
What would you like to do?
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