-
-
Save snuggs/f6e9dbe8a23804fc13060494cf1b66ac to your computer and use it in GitHub Desktop.
Simple standalone ActiveRecord setup.
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