Skip to content

Commit

Permalink
Bigrecord updates
Browse files Browse the repository at this point in the history
* Updated some documentation.
* Added generators for Bigrecord models in Rails.
* Added bigrecord rake tasks for Rails integration.
  • Loading branch information
greglu committed Sep 23, 2009
1 parent 6a70021 commit ac1881b
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 3 deletions.
9 changes: 8 additions & 1 deletion bigindex/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ A Rails plugin that drops into models and provides indexing functionality. Uses

This should be used in conjunction with BigRecord in order to provide a more complete ORM.

== Supported search servers

* Solr
* Sphinx (planned)

== Getting Started

Expand All @@ -21,9 +25,12 @@ Modify your Ruby class/model similarly to the following:

BigIndex will then override the default Model.find() method to pass through the indexer first. Model.find() will also accept the option {:bypass_index => true}, which bypasses the indexed #find method and dispatches it to the original Model.find() method, e.g. Model.find(:all, :bypass_index => true). Alternatively, you can use Model.find_without_index(:all) for the same functionality.

== License

Big Record is released under the MIT license.

= Links

* Contact Us
* Website - http://www.bigrecord.org
* IRC Channel - <tt>##bigrecord</tt> on irc.freenode.net
* IRC Channel - <tt>#bigrecord</tt> on irc.freenode.net
12 changes: 11 additions & 1 deletion bigrecord/doc/getting_started.rdoc
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
= Getting Started
= Getting Started

== Requirements

* Database set up (please refer to the database's own documentation) with the required information known such as host, port, username, password, etc.
* Big Record Driver (if your database requires it for connecting)
* JRuby 1.1.6+ is needed to run Big Record Driver.

== Installation

You have two options:
9 changes: 8 additions & 1 deletion bigrecord/examples/bigrecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ production:
zookeeper_quorum: localhost
zookeeper_client_port: 2183
drb_host: localhost
drb_port: 40002
drb_port: 40002

cassandra:
adapter: cassandra
address: localhost
port: 9160
drb_host: localhost
drb_port: 40003
28 changes: 28 additions & 0 deletions bigrecord/generators/bigrecord_model/bigrecord_model_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rails_generator/generators/components/model/model_generator'

class BigrecordModelGenerator < ModelGenerator

def manifest

record do |m|
# Check for class naming collisions.
m.class_collisions class_path, class_name

# Model, spec, and fixture directories.
m.directory File.join('app/models', class_path)
m.directory File.join('spec/models', class_path)

# Model class, spec and fixtures.
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
m.template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")

unless options[:skip_migration]
m.migration_template 'migration.rb', 'db/bigrecord_migrate', :assigns => {
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
end
end

end

end
12 changes: 12 additions & 0 deletions bigrecord/generators/bigrecord_model/templates/migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class <%= migration_name %> < BigRecord::Migration
def self.up
create_table :<%= table_name %>, :force => true do |t|
end
end

def self.down
drop_table :<%= table_name %>
end

end
2 changes: 2 additions & 0 deletions bigrecord/generators/bigrecord_model/templates/model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class <%= class_name %> < BigRecord::Base
end
12 changes: 12 additions & 0 deletions bigrecord/generators/bigrecord_model/templates/model_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')

describe <%= class_name %> do
before(:each) do
@valid_attributes = {
}
end

it "should create a new instance given valid attributes" do
<%= class_name %>.create!(@valid_attributes)
end
end
7 changes: 7 additions & 0 deletions bigrecord/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
target = File.join(config_dir, "bigrecord.yml")
alternate_target = File.join(config_dir, "bigrecord.yml.sample")

migration_dir = File.join(RAILS_ROOT, "db", "bigrecord_migrate")

if !File.exist?(target)
FileUtils.cp(source, target)
else
puts "[Bigrecord] RAILS_ROOT/config/bigrecord.yml file already exists. Copying it as bigrecord.yml.sample for reference."
FileUtils.cp(source, alternate_target)
end

unless File.exist?(migration_dir)
puts "[Bigrecord] Migration folder not found at \"#{migration_dir}\" Creating now..."
FileUtils.mkdir_p(migration_dir)
end
58 changes: 58 additions & 0 deletions bigrecord/tasks/bigrecord_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace :db do

desc "Migrate the Bigrecord database through scripts in db/bigrecord_migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
task :migrate => :environment do
Rake::Task["bigrecord:migrate"].invoke
end

end


namespace :bigrecord do

desc "Migrate the Bigrecord database through scripts in db/bigrecord_migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
task :migrate => :environment do
BigRecord::Migrator.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
BigRecord::Migrator.migrate("db/bigrecord_migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
end

namespace :migrate do
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
task :redo => :environment do
if ENV["VERSION"]
Rake::Task["bigrecord:migrate:down"].invoke
Rake::Task["bigrecord:migrate:up"].invoke
else
Rake::Task["bigrecord:rollback"].invoke
Rake::Task["bigrecord:migrate"].invoke
end
end

desc 'Runs the "up" for a given migration VERSION.'
task :up => :environment do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version
BigRecord::Migrator.run(:up, "db/bigrecord_migrate/", version)
end

desc 'Runs the "down" for a given migration VERSION.'
task :down => :environment do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version
BigRecord::Migrator.run(:up, "db/bigrecord_migrate/", version)
end
end

desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
task :rollback => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
BigRecord::Migrator.rollback('db/bigrecord_migrate/', step)
end

desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
task :forward => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
BigRecord::Migrator.forward('db/bigrecord_migrate/', step)
end

end

0 comments on commit ac1881b

Please sign in to comment.