forked from gsusmonzon/fast_sessions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gsusmonzon
committed
Apr 22, 2011
1 parent
a936b39
commit 0b3a9cb
Showing
3 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Description: | ||
Creates a migration to add the sessions table used by the FastSessions | ||
session store plugin. Pass the migration name, either CamelCased or under_scored, | ||
as an argument. | ||
|
||
Example: | ||
`./script/generate fast_session_migration CreateSessionTable` | ||
|
||
With 4 existing migrations, this creates the CreateSessionTable migration | ||
in db/migrate/005_add_session_table.rb | ||
|
29 changes: 29 additions & 0 deletions
29
lib/generators/fast_session_migration/fast_session_migration_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,29 @@ | ||
class FastSessionMigrationGenerator < Rails::Generators::NamedBase | ||
include Rails::Generators::Migration | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
def create_migration | ||
migration_template 'migration.rb', 'db/migrate/add_fast_sessions' | ||
end | ||
|
||
protected | ||
|
||
def default_session_table_name | ||
ActiveRecord::Base.pluralize_table_names ? 'fast_session'.pluralize : 'fast_session' | ||
end | ||
|
||
def session_table_name | ||
default_session_table_name | ||
end | ||
|
||
# FIXME: Should be proxied to ActiveRecord::Generators::Base | ||
# Implement the required interface for Rails::Generators::Migration. | ||
def self.next_migration_number(dirname) #:nodoc: | ||
if ActiveRecord::Base.timestamped_migrations | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
else | ||
"%.3d" % (current_migration_number(dirname) + 1) | ||
end | ||
end | ||
|
||
end |
20 changes: 20 additions & 0 deletions
20
lib/generators/fast_session_migration/templates/migration.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,20 @@ | ||
class <%= class_name %> < ActiveRecord::Migration | ||
ActiveRecord::SessionStore::FastSessions.table_name = "<%= session_table_name %>" | ||
# If you're going to use this module with MySQL 5.1.22+, then you'd | ||
# like to set this to +true+ because it will provide you with consecutive | ||
# data inserts in InnoDB. Another cases when you'd like to use it is when | ||
# your MySQL server is I/O bound now and you do not want to add random I/O | ||
# because of randomized primary key. | ||
ActiveRecord::SessionStore::FastSessions.use_auto_increment = false | ||
def self.up | ||
say "Creating sessions table..." | ||
ActiveRecord::SessionStore::FastSessions.create_table! | ||
end | ||
def self.down | ||
say "Destroying sessions table..." | ||
ActiveRecord::SessionStore::FastSessions.drop_table! | ||
end | ||
end |