README.rdoc in secondbase-0.3.3 vs README.rdoc in secondbase-0.4.0

- old
+ new

@@ -1,12 +1,12 @@ = secondbase -SecondBase adds a second database to your application. While Rails enables you to establish connections to as many external databases as you like, Rails can only manage a single database with it's migration and testing tasks. +Secondbase adds a second database to your application. While Rails enables you to establish connections to as many external databases as you like, Rails can only manage a single database with it's migration and testing tasks. Secondbase enables Rails to work with, and manage, a second database (almost) transparently. As a developer, you should not even realize a second database is in play. Core rake tasks such as db:create, db:migrate, and test will continue to work seamlessly with both databases without you, the developer, having to run any extra rake tasks. -== Contributing to secondbase +== Contributing to Secondbase * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch @@ -15,28 +15,26 @@ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. == System Requirements Secondbase now supports Rails 2.x and Rails 3.x. -== Known Issues -The custom migration generator does not work in Rails 2.x. The work around for the time being is to use the normal migration generator provided in Rails 2.x, and then move the migration to db/migrate/secondbase: - - ./script/generate migration CreateWidgetsTable - mv db/migrate/20101203211338_create_widgets_table.rb db/migrate/secondbase - == Installation Modify your Gemfile to include Secondbase: - gem 'secondbase', '0.3.0' + gem 'secondbase', '0.4.0' Run `bundle install`. You thought it would be harder? If you're using Rails 2.x, then yes, a little bit harder. You must also add this to your Rakefile: - require 'secondbase/tasks' + require 'secondbase/tasks' if defined?(Secondbase) +PLEASE NOTE that if you are using bundler with Rails 2.x, then you simply need to add this to your Rakefile: + + require 'secondbase/tasks' + == Usage === Database -Configure your database.yml to define your secondbase: +Configure your database.yml to define your Secondbase: # Your normal rails definitions... development: adapter: mysql #postgres, oracle, etc encoding: utf8 @@ -60,13 +58,17 @@ database: secondbase_test === Migrations SecondBase comes with a generator to assist in managing your migrations - + +Rails 3.x: rails generator secondbase:migration CreateWidgetsTable +Rails 2.x: + script/generate secondbase_migration CreateWidgetsTable + The generator will organize your second (data)base migrations alongside of your primary database. The above command will generate the file: db/migrate/secondbase/20101203211338_create_widgets_table.rb To run your migrations, simply run: @@ -97,10 +99,17 @@ class Widget < SecondBase::Base # you're Widget model is now pointing to your second (data)base table 'widgets' end +ActiveRecord associations will still work between your Firstbase and Secondbase models! + + # Notice how normal this all looks... + class User < ActiveRecord::Base + has_many :widgets + end + === Rake Tasks & Custom Classes If you need to write rake tasks, or some other code that does not extend ActiveRecord, you can simply establish a connection to your second (data)base: SecondBase::has_runner(Rails.env) @@ -113,18 +122,18 @@ require 'secondbase/fixtures' This is patch to fixtures that will identify the fixtures which belong to models that extend SecondBase::Base. The patch will then ensure that the table descendants of SecondBase::Base get loaded into your second test (data)base. -At this time, there is not support for anything other than fixtures (i.e. factories). If you have the time to update this gem to be test object compatible, by all means... +At this time, I can verify that Secondbase works with Fixtures and Machinist. Conceivably, other test factories should work (like Factory Girl), but there is currently no support for this. If you have the time to update this gem to be test object compatible, by all means... == TODO -- Migration generator needs support for attribute generation (similar to rails generate migration). For example: - `rails generate secondbase_migration AddTitleBodyToPost title:string body:text published:boolean` +- Migration generator in Rails 3.x needs support for attribute generation (similar to rails generate migration). For example: + `rails generate secondbase:migration AddTitleBodyToPost title:string body:text published:boolean` - rake db:fixtures:load is currently broken. Like many other things I have fixed, it assumes you only one a single database and attempts to load all fixtures into it. I don't believe we can get away with alias chaining this one, I think (like the Fixtures class), we'll have to freedom patch it. -- secondbase should provide support for testing objects other then fixtures +- secondbase needs to be tested with other factory frameworks (other then Fixtures and Machinist) - TESTS!! Not 100% sure how to test the rake tasks, but I can definitely write tests for the classes and generators. I did this in my spare time, sorry... == Copyright