Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/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