Skip to content

Instantly share code, notes, and snippets.

@willnet
Created July 13, 2010 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willnet/473736 to your computer and use it in GitHub Desktop.
Save willnet/473736 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# ActiveRecordで管理している古いsessionを削除するスクリプト
# デフォルトで14日以上前のレコードを削除
ENV["RAILS_ENV"] ||= "production"
require File.dirname(__FILE__) + '/../config/boot'
require File.dirname(__FILE__) + '/../config/environment'
num = ARGV.shift || 14
num = num.to_i
# puts RAILS_ENV
# puts "DELETE FROM sessions where #{num.days.ago.to_s(:db)} > created_at;"
ActiveRecord::Base.connection.execute "DELETE FROM sessions where '#{num.days.ago.to_s(:db)}' > updated_at;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment