Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds migration generator for tags and taggings tables

  • Loading branch information...
commit 1cd799b9b4e8e3c15a0e49acda17a6a0cf6a33d3 1 parent cde8678
Daniel Haran authored
View
7 generators/is_taggable_migration/is_taggable_migration_generator.rb
@@ -0,0 +1,7 @@
+class IsTaggableMigrationGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => 'is_taggable_migration'
+ end
+ end
+end
View
24 generators/is_taggable_migration/templates/migration.rb
@@ -0,0 +1,24 @@
+class IsTaggableMigration < ActiveRecord::Migration
+ def self.up
+ create_table :tags do |t|
+ t.string :name, :default => ''
+ t.string :kind, :default => ''
+ end
+
+ create_table :taggings do |t|
+ t.integer :tag_id
+
+ t.string :taggable_type, :default => ''
+ t.integer :taggable_id
+ end
+
+ add_index :tags, [:name, :kind]
+ add_index :taggings, :tag_id
+ add_index :taggings, [:taggable_id, :taggable_type]
+ end
+
+ def self.down
+ drop_table :taggings
+ drop_table :tags
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.