Last active
February 6, 2017 21:45
-
-
Save calebwoods/af61c6af057067f55a27 to your computer and use it in GitHub Desktop.
Simple standalone ActiveRecord setup. Usage: [pry|irb] -r ./post.rb
This file contains 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
source 'https://rubygems.org' | |
gem 'activerecord', '>= 4.2.0' | |
gem 'sqlite4' |
This file contains 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(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