Skip to content

Instantly share code, notes, and snippets.

@revskill
Last active August 29, 2015 14:09
Show Gist options
  • Save revskill/d98839f39f21ea193044 to your computer and use it in GitHub Desktop.
Save revskill/d98839f39f21ea193044 to your computer and use it in GitHub Desktop.
Ruby ActiveRecord configuration
require 'active_record'
require 'sqlite3' # or 'pg' or 'sqlite3'
# Change the following to reflect your database settings
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3', # or 'postgresql' or 'sqlite3'
database: 'health.sqlite'
)
ActiveRecord::Schema.define do
unless ActiveRecord::Base.connection.tables.include? 'albums'
create_table :albums do |table|
table.column :title, :string
table.column :performer, :string
end
end
unless ActiveRecord::Base.connection.tables.include? 'tracks'
create_table :tracks do |table|
table.column :album_id, :integer # foreign key <table-name-singular>_id (i.e. this is the primary key from the 'albums' table)
table.column :track_number, :integer
table.column :title, :string
end
end
end
require_relative './config'
class Health < ActiveRecord::Base
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment