Skip to content

Commit

Permalink
Add a generator for db migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
obrie committed Mar 1, 2010
1 parent b8ea03c commit 631308f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
@@ -1,5 +1,6 @@
== master

* Add a generator for db migrations
* Release gems via rake-gemcutter instead of rubyforge
* By default, sort messages newest first [Alexander Lang]

Expand Down
11 changes: 11 additions & 0 deletions README.rdoc
Expand Up @@ -33,6 +33,17 @@ demonstrating a reference implementation of these features.

== Usage

=== Installation

+has_messages+ requires additional database tables to work. You can generate
a migration for these tables like so:

script/generate has_messages

Then simply migrate your database:

rake db:migrate

=== Adding message support

class User < ActiveRecord::Base
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ spec = Gem::Specification.new do |s|
s.summary = 'Demonstrates a reference implementation for sending messages between users in ActiveRecord'
s.description = s.summary

s.files = FileList['{app,db,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
s.files = FileList['{app,generators,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
s.require_path = 'lib'
s.has_rdoc = true
s.test_files = Dir['test/**/*_test.rb']
Expand Down
5 changes: 5 additions & 0 deletions generators/has_messages/USAGE
@@ -0,0 +1,5 @@
Usage:

script/generate has_messages

This will create migrations that will add the proper tables to store messages.
9 changes: 9 additions & 0 deletions generators/has_messages/has_messages_generator.rb
@@ -0,0 +1,9 @@
class HasMessagesGenerator < Rails::Generator::Base
def manifest
record do |m|
m.migration_template '001_create_messages.rb', 'db/migrate', :migration_file_name => 'create_messages'
m.sleep 1
m.migration_template '002_create_message_recipients.rb', 'db/migrate', :migration_file_name => 'create_message_recipients'
end
end
end
File renamed without changes.
File renamed without changes.
@@ -1,12 +1,12 @@
class MigrateHasMessagesToVersion2 < ActiveRecord::Migration
def self.up
ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../generators/has_messages/templates", 0).migrations.each do |migration|
migration.migrate(:up)
end
end

def self.down
ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
ActiveRecord::Migrator.new(:down, "#{Rails.root}/../../generators/has_messages/templates", 0).migrations.each do |migration|
migration.migrate(:down)
end
end
Expand Down

0 comments on commit 631308f

Please sign in to comment.