Skip to content

Commit

Permalink
Added a generator to create the amazon_products database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
David Eisinger committed Jul 3, 2008
1 parent 64207a6 commit 1e678ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
13 changes: 4 additions & 9 deletions README
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ existing model.
== Setup == Setup


This code does not require changing any current database tables. It only requires This code does not require changing any current database tables. It only requires
adding one migration for a single new table used to cache responses from Amazon: adding one migration for a single new table used to cache responses from Amazon.

Run the following to create the migration:
ActiveRecord::Base.connection.create_table :amazon_products do |t|
t.column :asin, :string script/generate acts_as_amazon_product_migration
t.column :xml, :text
t.column :created_at, :datetime, :null => false
t.column :amazonable_id, :integer, :default => 0, :null => false
t.column :amazonable_type, :string, :limit => 15, :default => "", :null => false
end


== Using acts_as_amazon_product == Using acts_as_amazon_product


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
class ActsAsAmazonProductMigrationGenerator < Rails::Generator::Base
def manifest
record do |m|
m.migration_template 'migration.rb', 'db/migrate'
end
end

def file_name
"acts_as_amazon_product_migration"
end
end
16 changes: 16 additions & 0 deletions generators/acts_as_amazon_product_migration/templates/migration.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
class ActsAsAmazonProductMigration < ActiveRecord::Migration
def self.up
create_table :amazon_products do |t|
t.string :asin
t.text :xml
t.integer :amazonable_id, :default => 0, :null => false
t.string :amazonable_type, :limit => 15, :default => "", :null => false

t.timestamps
end
end

def self.down
drop_table :amazon_products
end
end

0 comments on commit 1e678ef

Please sign in to comment.