Created
January 15, 2012 23:21
-
-
Save rwboyer/1617938 to your computer and use it in GitHub Desktop.
Rakefile for postgres issue
This file contains hidden or 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 'lib/model/product' | |
| class CreateProducts < ActiveRecord::Migration | |
| def self.up | |
| create_table :products do |t| | |
| t.string :pnumber, :null => false | |
| t.string :image, :null => false | |
| t.string :name, :null => false | |
| t.decimal :price, :null => false #, :precision => 8, :scale => 2 | |
| t.string :description, :null => false | |
| t.string :download, :null => true | |
| t.string :detail, :null => true | |
| end | |
| Product.create({ | |
| :pnumber => "101", | |
| :image => "images/landscapex1.jpg", | |
| :name => "The Photographer's Eye Landscape 1", | |
| :download => "/Users/rwboyer/Desktop/TPE-Landscapes-1.pdf", | |
| :price => 4.99, | |
| :detail => '', | |
| :description => "A collection of 10 landscape images and the story of how they were made. Includes 10 tips for better landscape images." }) | |
| Product.create({ | |
| :pnumber => "102", | |
| :image => "images/people_1.jpg", | |
| :name => "The Photographer's Eye People 1", | |
| :download => "/Users/rwboyer/Desktop/people1-final.pdf", | |
| :price => 4.99, | |
| :detail => '', | |
| :description => "Ten of my best images of people along with how they were made. Contains a bonus section of my top 10 tips for better images of people." }) | |
| end | |
| def self.down | |
| drop_table :products | |
| end | |
| end |
This file contains hidden or 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 'digest/sha1' | |
| require 'lib/model/user' | |
| class CreateUsers < ActiveRecord::Migration | |
| def self.up | |
| create_table :users do |t| | |
| t.string :username, :null => false, :limit => 40 | |
| t.string :password, :null => false, :limit => 40 | |
| end | |
| User.create({ :username => "steph@endpoint.com", | |
| :password => Digest::SHA1.hexdigest("password") }) | |
| end | |
| def self.down | |
| drop_table :users | |
| end | |
| end |
This file contains hidden or 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 'lib/model/dlitem.rb' | |
| class CreateDlitem < ActiveRecord::Migration | |
| def self.up | |
| create_table :dlitems do |t| | |
| t.string :pnumber, :null => false | |
| t.string :order, :null => false | |
| t.string :key, :null => true | |
| t.integer :count, :null => false | |
| end | |
| end | |
| def self.down | |
| drop_table :products | |
| end | |
| end |
This file contains hidden or 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
| class CreatePages < ActiveRecord::Migration | |
| def self.up | |
| create_table :pages do |t| | |
| t.string :title, :null => false | |
| t.string :slug, :null => false | |
| t.text :content | |
| end | |
| end | |
| def self.down | |
| drop_table :pages | |
| end | |
| end |
This file contains hidden or 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
| $: << "." | |
| namespace :db do | |
| task :environment do | |
| require 'rubygems' | |
| require 'logger' | |
| require 'active_record' | |
| require 'uri' | |
| #ActiveRecord::Base.establish_connection :adapter => 'sqlite3', | |
| #:database => 'db/development.sqlite3.db' | |
| if ENV['RACK_ENV'] == 'production' | |
| puts "connecting to postgresql" | |
| db = URI.parse(ENV['DATABASE_URL']) | |
| ActiveRecord::Base.establish_connection( | |
| :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme, | |
| :host => db.host, | |
| :username => db.user, | |
| :password => db.password, | |
| :database => db.path[1..-1], | |
| :encoding => 'utf8' | |
| ) | |
| else | |
| puts "connecting to sqlite3" | |
| ActiveRecord::Base.establish_connection( | |
| :adapter => 'sqlite3', | |
| :database => 'db/development.sqlite3.db' | |
| ) | |
| end | |
| #ActiveMerchant::Billing::Base.mode = :test | |
| end | |
| desc "Migrate the database" | |
| task(:migrate => :environment) do | |
| ActiveRecord::Base.logger = Logger.new(STDOUT) | |
| ActiveRecord::Migration.verbose = true | |
| ActiveRecord::Migrator.migrate("db/migrate") | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment