Skip to content

Instantly share code, notes, and snippets.

@snuggs
Forked from calebwoods/Gemfile
Last active November 18, 2020 22:48
Show Gist options
  • Save snuggs/f6e9dbe8a23804fc13060494cf1b66ac to your computer and use it in GitHub Desktop.
Save snuggs/f6e9dbe8a23804fc13060494cf1b66ac to your computer and use it in GitHub Desktop.
Simple standalone ActiveRecord setup.
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