aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/active_record/session_migration
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-09-24 14:01:31 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-09-24 16:11:41 -0700
commitf0dd77c6be6a86fe384bb0015151e0a497973d39 (patch)
treead81bb4c807c39edeaa37035882a16d9d95ebaa9 /railties/lib/rails/generators/active_record/session_migration
parent610b81beca461a6fa4f00c7023e0e4315eb2b8be (diff)
downloadrails-f0dd77c6be6a86fe384bb0015151e0a497973d39.tar.gz
rails-f0dd77c6be6a86fe384bb0015151e0a497973d39.tar.bz2
rails-f0dd77c6be6a86fe384bb0015151e0a497973d39.zip
Move railties/lib/* into railties/lib/*
Diffstat (limited to 'railties/lib/rails/generators/active_record/session_migration')
-rw-r--r--railties/lib/rails/generators/active_record/session_migration/session_migration_generator.rb24
-rw-r--r--railties/lib/rails/generators/active_record/session_migration/templates/migration.rb16
2 files changed, 40 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/active_record/session_migration/session_migration_generator.rb b/railties/lib/rails/generators/active_record/session_migration/session_migration_generator.rb
new file mode 100644
index 0000000000..afcda2a98a
--- /dev/null
+++ b/railties/lib/rails/generators/active_record/session_migration/session_migration_generator.rb
@@ -0,0 +1,24 @@
+require 'rails/generators/active_record'
+
+module ActiveRecord
+ module Generators
+ class SessionMigrationGenerator < Base
+ argument :name, :type => :string, :default => "add_sessions_table"
+
+ def create_migration_file
+ migration_template "migration.rb", "db/migrate/#{file_name}.rb"
+ end
+
+ protected
+
+ def session_table_name
+ current_table_name = ActiveRecord::SessionStore::Session.table_name
+ if ["sessions", "session"].include?(current_table_name)
+ current_table_name = (ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session')
+ end
+ current_table_name
+ end
+
+ end
+ end
+end
diff --git a/railties/lib/rails/generators/active_record/session_migration/templates/migration.rb b/railties/lib/rails/generators/active_record/session_migration/templates/migration.rb
new file mode 100644
index 0000000000..919822af7b
--- /dev/null
+++ b/railties/lib/rails/generators/active_record/session_migration/templates/migration.rb
@@ -0,0 +1,16 @@
+class <%= migration_class_name %> < ActiveRecord::Migration
+ def self.up
+ create_table :<%= session_table_name %> do |t|
+ t.string :session_id, :null => false
+ t.text :data
+ t.timestamps
+ end
+
+ add_index :<%= session_table_name %>, :session_id
+ add_index :<%= session_table_name %>, :updated_at
+ end
+
+ def self.down
+ drop_table :<%= session_table_name %>
+ end
+end