@Fryguy thnx - it should be:
Metric.where(:id => Metric.where('timestamp < ?', 4.hours.ago).limit(100)).delete_all
otherwise we'd just use:
Metric.where('timestamp < ?', 4.hours.ago)).delete_all
also, we use arel/config values in the actual generation there. I simplified for the room
truncatestrategy instead of our current delete with batches mode?
MetricRollupsince that has a dependant table, but
metricsseems ripe for the picking
ActiveRecord, for this one query, could you change the query. I think
tablenamecan be a lambda. maybe that will be it
You'd have to make your own
with_table and just set the table metadata on the model if you want that sort of thing over just using arel. Rails doesn't provide any sort of dynamic 'use this table name for this query' that I'm aware of.
def self.with_table(table_name) # Save the old table name somehow, whatever... @old_table_name = self.table_name begin self.table_name = table_name yield ensure self.table_name = @old_table_name end end
^ totally making this up, haven't tried it.
Metric.with_table(:metrics_2) do create(:timestamp => blah) end