forked from openplaces/bigrecord
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated some documentation. * Added generators for Bigrecord models in Rails. * Added bigrecord rake tasks for Rails integration.
- Loading branch information
Showing
9 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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: |
This file contains 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
28 changes: 28 additions & 0 deletions
28
bigrecord/generators/bigrecord_model/bigrecord_model_generator.rb
This file contains 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
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
12
bigrecord/generators/bigrecord_model/templates/migration.rb
This file contains 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
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 |
This file contains 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
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
12
bigrecord/generators/bigrecord_model/templates/model_spec.rb
This file contains 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
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 |
This file contains 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
This file contains 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
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 |