Rails 2.1 migration

I’ve hacked together a simple script for converting timezones from the local timezone to utc for Rails 2.1

        #!env ruby
        class DummyTable
          def initialize(tablename)
            @@tablename=tablename
          end
          def self.method_missing(m, *args); end
          
          def self.datetime(name,options={})
            puts "execute \"UPDATE #{@@tablename} SET #{name}=CONVERT_TZ(#{name},'SYSTEM','+00:00');\""
          end
        end
        
        def create_table(tablename,options,*block)
          dummy_table=DummyTable.new(tablename)
          yield DummyTable
        end
        
        def add_index(name,fields,options={}); end
        
        class ActiveRecord;end
        
        class ActiveRecord::Schema
          def self.define(options={}, *block)
            yield
          end
        end
        
        require 'db/schema.rb'
        

Drop this file in the root of your project and just run it with plain Ruby. I wrote it this way so I could avoid ActiveRecord, it will spit out a bunch of execute commands ready for plugging in to a migration

Jun 17 2008 14:23 | Tags: rails timezone migration | 32 comments

Comments

New Comment