Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

This project is archived and is in readonly mode.

db:sessions:clear to respect legacy table names

#2745

rake db:sessions:clear has the table name for the sessions table hardcoded. Since the sessions table name is configurable trough:

ActiveRecord::SessionStore::Session.table_name=

wouldn't it make sense that the task uses the table name defined above?
Tested patch attached...

Reported by felipekaufmann · June 2nd, 2009 @ 06:40 PM

State: resolved
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from databases.rake, minor, patch to bugmash, databases.rake, minor, patch

    August 7th, 2009 @ 01:41 PM

  2. pjammer
    pjammer

    +1 for this patch. it gives the same functionality as the previous rails version. +1 on the relevance of this ticket. While the code is cleaner, someone who have to change the name of the sessions table manually in order for the name to be changed. With the existing code, the rake task wouldn't work.

    However, can you pass an argument to the db:sessions:create task? if not, the only way to change the name is to muck around in the migration.

    August 8th, 2009 @ 04:34 AM

  3. Elad Meidar
    Elad Meidar

    +1 for the first patch, +1 for relevancy.

    You can change the name by specifying:

     ActiveRecord::SessionStore::Session.table_name = 'new_session_table_name'
    

    in environment.rb

    Although the patch fixed db:sessions:clear to to use the custom session table name, it didn't apply to db:sessions:create as pjammer applied, i attached a patch that fixes this issue by overriding the default_table_name method in sessions_generator.rb

    few things to keep in mind:

    • i thought it would be wise to leave the pluralization conditional in tact, in case there is no custom table name (e.c table is still 'sessions' or 'session').
    • i supplied a basic test to ensure that the generator is using the right table name, but i did not check the content of the generated migration, i was unable to run the generator.

    tried:

    g = Rails::Generator::Base.instance('session_migration')
    g.command(:create).invoke!
    

    which resulted in:

    undefined method `timestamped_migrations' for ActiveRecord::Base:Class
    

    August 8th, 2009 @ 04:14 PM

  4. Elad Meidar
    Elad Meidar

    Sorry, patch apply to 2-3-stable, not master.

    August 8th, 2009 @ 04:51 PM

  5. Elad Meidar
  6. Dan Croak
    Dan Croak

    What tests should be run to verify this patch?

    The fix_sessions patch applies cleanly in 2-3-stable and rake test runs green for railties.

    However, I'm not sure I'm running the right tests.

    August 8th, 2009 @ 10:34 PM

  7. Blue Box Jesse
    Blue Box Jesse

    +1

    Patch applies cleanly on 2-3-stable.

    Railties tests pass.

    Seems ready to go!

    September 26th, 2009 @ 10:32 PM

  8. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from bugmash, databases.rake, minor, patch to bugmash-review, databases.rake, minor, patch

    September 27th, 2009 @ 11:43 AM

  9. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  10. Rizwan Reza
    Rizwan Reza
    • Tag changed from bugmash-review, databases.rake, minor, patch to bugmash, databases.rake, minor, patch

    May 15th, 2010 @ 06:45 PM

  11. Priit Tamboom
    Priit Tamboom

    It looks like master's db:sessions:clean already honors
    ActiveRecord::SessionStore::Session.table_name:
    http://github.com/rails/rails/blob/master/activerecord/lib/active_r...

    and master's db:sessions:create also honors custom table_name:
    http://github.com/rails/rails/blob/master/activerecord/lib/rails/ge...

    I suggest we can call this ticket fixed for master.

    May 15th, 2010 @ 09:24 PM

  12. Priit Tamboom
    Priit Tamboom

    +1 to close the ticket because fix it's already in master

    May 15th, 2010 @ 09:57 PM

  13. jslag
    jslag

    Agree with Priit, master already gets this right.

    +1 to closing the ticket.

    May 15th, 2010 @ 10:28 PM

  14. Rizwan Reza
    Rizwan Reza
    • Tag changed from bugmash, databases.rake, minor, patch to databases.rake, minor, patch
    • State changed from new to resolved

    May 16th, 2010 @ 03:46 AM