Dynamic Table Names for Daily Tables


#1

Hi guys,

I have a problem with a legacy database that has a sequence of daily
tables (generated elsewhere) of the form

Header090501
Daily090501
Extra090501
Detail090501
Header090502
Daily090502
Extra090502
Detail090502
Header090503… etc.

In addition, I’m using ar-extensions and composite primary keys, with a
slight monkeypatch to get them working together for bulk inserts.

My definition is currently like:

module Legacy
class Header < ActiveRecord::Base
set_table_name “Header#{Time.now.strftime(”%y%m%d")}"
set_primary_keys “ResultID”
end
end

All this is working fine, right up until midnight, when the tables
should change, but of course my definition is only dynamic if it is run
again. Since I have long running jobs that need to run across the time
boundaries, I thought that the best thing to do would be to call

Header::set_table_name

from the initialization of the interface that first attaches to the
database. This isn’t strictly speaking Rails code, but relies heavily on
ActiveRecord, ActiveSupport etc. Is there a more conventional way to
handle this sort of thing?

Mac