Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 13770c9ebb4363eb7c1a7a2177d91606d19ede25 0 parents
@colszowka authored
3  .gitignore
@@ -0,0 +1,3 @@
+config/database.yml
+log/*
+db/*.sqlite3
0  README.textile
No changes.
37 Rakefile
@@ -0,0 +1,37 @@
+task :environment do
+ require 'init'
+end
+
+desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
+task :migrate => :environment do
+ ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
+end
+
+namespace :generate do
+ desc "Generate a migration with given name. Specify migration name with NAME=my_migration_name"
+ task :migration => :environment do
+ raise "Please specify desired migration name with NAME=my_migration_name" unless ENV['NAME']
+
+ migration_name = ENV['NAME'].strip.chomp
+
+ migrations_path = File.join(File.dirname(__FILE__), 'db', 'migrate')
+
+ # Find the highest existing migration version
+ if (existing_migrations = Dir[File.join(migrations_path, '*.rb')]).length > 0
+ version = File.basename(existing_migrations.sort.reverse.first)[/^(\d+)_/,1].to_i + 1
+ else
+ version = 1
+ end
+
+ migrations_template = File.read(File.join(migrations_path, 'migration.template') )
+
+ migration_content = migrations_template.gsub('__migration_name__', migration_name.camelize)
+ migration_filename = "#{"%03d" % version}_#{migration_name}.rb"
+
+ File.open(File.join(migrations_path, migration_filename), "w+") do |migration|
+ migration.puts migration_content
+ end
+
+ puts "Successfully created migration #{migration_filename}"
+ end
+end
22 config/database.sample.yml
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
12 db/migrate/migration.template
@@ -0,0 +1,12 @@
+class __migration_name__ < ActiveRecord::Migration
+ def self.up
+ # create_table :users do |t|
+ # t.string :name, :null => false
+ # end
+ end
+
+ def self.down
+ # drop_table :users
+ end
+end
+
14 init.rb
@@ -0,0 +1,14 @@
+require 'activesupport'
+require 'activerecord'
+
+# Find environment
+RACK_ENV = ENV['RACK_ENV'] || 'development' unless defined? RACK_ENV
+
+# Load db config and establish connection
+ActiveRecord::Base.establish_connection YAML.load(File.read(File.join(File.dirname(__FILE__), 'config', 'database.yml'))).with_indifferent_access[RACK_ENV]
+
+# Setup logger for activerecord
+ActiveRecord::Base.logger = Logger.new(File.open(File.join(File.dirname(__FILE__), 'log', "#{RACK_ENV}.log"), 'a'))
+
+# Load libs from lib/
+Dir[File.join(File.dirname(__FILE__), 'lib', '*.rb')].each {|lib| require lib }
0  lib/.gitignore
No changes.
0  log/.gitignore
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.