Skip to content

Instantly share code, notes, and snippets.

@rennex
Last active August 29, 2015 14:15
Show Gist options
  • Save rennex/f46c598bf865b9d87e92 to your computer and use it in GitHub Desktop.
Save rennex/f46c598bf865b9d87e92 to your computer and use it in GitHub Desktop.
DB setup skeleton for Sequel
The files shown below let you define the location of the database in one place,
and easily run migrations, the main web app, and any backend utility scripts.
# do this in the web app or utility script:
require_relative "database.rb"
# to run migrations (in the shell):
$ ./migrate
Files: (sorry for the format, but Gist doesn't allow subdirectories in file names)
---- database.rb ----
require_relative "db/initdb.rb"
class MyModel < Sequel::Model
# etc
end
---- db/initdb.rb ----
# this file initializes the DB connection
# some requires in case this is loaded by a utility script instead of the main app
require "bundler/setup"
require "sequel"
DB = Sequel.connect(File.read(File.dirname(__FILE__) + "/db_uri").chomp)
---- db/db_uri ----
postgres:///dbname
---- migrate ----
#!/bin/bash
sequel -m db/migrations/ "$@" `cat db/db_uri`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment