forked from parndt/friendly_id
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added upgrade migration. Tweaked README.
- Loading branch information
Norman Clarke
committed
Dec 19, 2008
1 parent
893d08d
commit a77ee14
Showing
5 changed files
with
87 additions
and
11 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
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
11 changes: 11 additions & 0 deletions
11
generators/friendly_id_20_upgrade/friendly_id_20_upgrade_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,11 @@ | ||
class FriendlyId20UpgradeGenerator < Rails::Generator::Base | ||
def manifest | ||
record do |m| | ||
unless options[:skip_migration] | ||
m.migration_template( | ||
'upgrade_friendly_id_to_20.rb', 'db/migrate', :migration_file_name => 'upgrade_friendly_id_to_20' | ||
) | ||
end | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
generators/friendly_id_20_upgrade/templates/upgrade_friendly_id_to_20.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,19 @@ | ||
class UpgradeFriendlyIdTo20 < ActiveRecord::Migration | ||
|
||
def self.up | ||
remove_column :slugs, :updated_at | ||
remove_index :slugs, :column => [:name, :sluggable_type] | ||
add_column :slugs, :sequence, :integer, :null => false, :default => 1 | ||
add_column :slugs, :scope, :string, :limit => 40 | ||
add_index :slugs, [:name, :sluggable_type, :scope, :sequence], :unique => true, :name => "index_slugs_on_n_s_s_and_s" | ||
end | ||
|
||
def self.down | ||
remove_index :slugs, :name => "index_slugs_on_n_s_s_and_s" | ||
remove_column :slugs, :scope | ||
remove_column :slugs, :sequence | ||
add_column :slugs, :updated_at, :datetime | ||
add_index :slugs, [:name, :sluggable_type], :unique => true | ||
end | ||
|
||
end |