Last active
August 29, 2015 14:09
-
-
Save revskill/d98839f39f21ea193044 to your computer and use it in GitHub Desktop.
Ruby ActiveRecord configuration
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' # 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 |
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_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