Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Database configuration and models

  • Loading branch information...
commit 9b356afef2b0fd6abf400f3c874129242e75840e 1 parent 26a73a7
Daniel MacDougall authored May 23, 2012
2  Gemfile
@@ -6,6 +6,8 @@ gem "unicorn"
6 6
 gem "pathological"
7 7
 gem "pinion"
8 8
 gem "sass"
  9
+gem "sequel"
  10
+gem "pg"
9 11
 
10 12
 group :development do
11 13
   gem "foreman"
2  Rakefile
... ...
@@ -0,0 +1,2 @@
  1
+require "bundler/setup"
  2
+require "pathological"
4  environment.rb
... ...
@@ -0,0 +1,4 @@
  1
+DB_HOST = "localhost"
  2
+DB_NAME = "app"
  3
+DB_USER = "postgres"
  4
+DB_PASS = ""
8  lib/models.rb
... ...
@@ -0,0 +1,8 @@
  1
+require "sequel"
  2
+require "pathological"
  3
+require "environment"
  4
+
  5
+DB = Sequel.postgres( :host => DB_HOST, :user => DB_USER, :password => DB_PASS, :database => DB_NAME)
  6
+
  7
+model_files = Dir[File.join(File.dirname(File.dirname(__FILE__)), "models") + "/*.rb"]
  8
+model_files.each { |file| require file }
9  script/console.rb
... ...
@@ -0,0 +1,9 @@
  1
+#!/usr/bin/env ruby-local-exec
  2
+
  3
+require "bundler/setup"
  4
+require "pathological"
  5
+require "irb"
  6
+require "lib/models"
  7
+
  8
+IRB.start
  9
+
30  script/create_migration.rb
... ...
@@ -0,0 +1,30 @@
  1
+#!/usr/bin/env ruby-local-exec
  2
+
  3
+require "fileutils"
  4
+
  5
+name = ARGV[0]
  6
+
  7
+if name.nil?
  8
+  puts "Usage: ruby create_migration name_of_migration"
  9
+  exit 1
  10
+end
  11
+
  12
+migrations_directory = File.join(File.dirname(File.dirname(__FILE__)), "migrations/")
  13
+FileUtils.mkdir_p migrations_directory
  14
+
  15
+timestamp = Time.now.strftime("%Y%m%d%H%M%S") # yyyymmddhhmmss
  16
+filename = File.join(migrations_directory, "#{timestamp}_#{name}.rb")
  17
+
  18
+File.open(filename, "w") do |f|
  19
+  f.puts <<EOF
  20
+Sequel.migration do
  21
+  up do
  22
+  end
  23
+
  24
+  down do
  25
+  end
  26
+end
  27
+EOF
  28
+end
  29
+
  30
+puts filename
9  script/run_migrations.rb
... ...
@@ -0,0 +1,9 @@
  1
+#!/usr/bin/env ruby-local-exec
  2
+
  3
+require "bundler/setup"
  4
+require "pathological"
  5
+require "environment"
  6
+
  7
+command = "bundle exec sequel -m migrations/"
  8
+db_url = "postgres://#{DB_HOST}/#{DB_NAME}"
  9
+puts `#{command} #{db_url}`

0 notes on commit 9b356af

Phil Crosby

I see you've built sinatra apps like this 10 times, but on which have you used postgres?

Daniel MacDougall

I started using it on the side project that was the catalyst for writing this skeleton, and I haven't looked back. It's nice to use a database that's not stuck in 1990. (utf-8 by default??)

Phil Crosby

You can keep your wretched utf8. If latin1 ain't broke, don't fix it.

Please sign in to comment.
Something went wrong with that request. Please try again.