mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
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
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user