Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 3de8239a7c93aed5883aaa00e36086b0c3e1572f 1 parent f91096a
@jeremy jeremy authored
View
2  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]
View
8 railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb
@@ -6,7 +6,13 @@ def initialize(runtime_args, runtime_options = {})
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
View
6 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
View
4 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
Please sign in to comment.
Something went wrong with that request. Please try again.