Forum: Ruby on Rails Dynamic Table Names for Daily Tables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
14ef30c2c4045716b7112fdf93389df8?d=identicon&s=25 Paul Mckibbin (blackrat)
on 2009-05-20 12:15
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
This topic is locked and can not be replied to.