aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-05-22 21:09:47 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-05-22 21:09:47 +0000
commit3de8239a7c93aed5883aaa00e36086b0c3e1572f (patch)
tree0ae9feadbfd5212b93b00296f6545d7447ddf661
parentf91096a543895a49876ec8e276cefefff6fdbe5a (diff)
downloadrails-3de8239a7c93aed5883aaa00e36086b0c3e1572f.tar.gz
rails-3de8239a7c93aed5883aaa00e36086b0c3e1572f.tar.bz2
rails-3de8239a7c93aed5883aaa00e36086b0c3e1572f.zip
Session migration generator obeys pluralize_table_names. Closes #5145.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4360 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb8
-rw-r--r--railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb6
-rw-r--r--railties/lib/tasks/databases.rake4
4 files changed, 15 insertions, 5 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 2a0aee1819..2655d1a0c5 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Session migration generator obeys pluralize_table_names. #5145 [james.adam@gmail.com]
+
* rake test:recent understands subdirectories. #2925 [jerrett@bravenet.com]
* The app generator detects the XAMPP package's MySQL socket location. #3832 [elliot@townx.org]
diff --git a/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb b/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb
index a513fa5cbf..2e177033a1 100644
--- a/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb
+++ b/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb
@@ -6,7 +6,13 @@ class SessionMigrationGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
- m.migration_template 'migration.rb', 'db/migrate'
+ m.migration_template 'migration.rb', 'db/migrate',
+ :assigns => { :session_table_name => default_session_table_name }
end
end
+
+ protected
+ def default_session_table_name
+ ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session'
+ end
end
diff --git a/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb b/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb
index 0ab7fcb1e9..c76bd8dde4 100644
--- a/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb
+++ b/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb
@@ -1,15 +1,15 @@
class <%= class_name %> < ActiveRecord::Migration
def self.up
- create_table :sessions do |t|
+ create_table :<%= session_table_name %> do |t|
t.column :session_id, :string
t.column :data, :text
t.column :updated_at, :datetime
end
- add_index :sessions, :session_id
+ add_index :<%= session_table_name %>, :session_id
end
def self.down
- drop_table :sessions
+ drop_table :<%= session_table_name %>
end
end
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake
index 4c85263398..4394febd03 100644
--- a/railties/lib/tasks/databases.rake
+++ b/railties/lib/tasks/databases.rake
@@ -151,7 +151,9 @@ namespace :db do
desc "Clear the sessions table"
task :clear => :environment do
- ActiveRecord::Base.connection.execute "DELETE FROM sessions"
+ session_table = 'session'
+ session_table = Inflector.pluralize(session_table) if ActiveRecord::Base.pluralize_table_names
+ ActiveRecord::Base.connection.execute "DELETE FROM #{session_table}"
end
end
end