]> git.openstreetmap.org Git - rails.git/commitdiff
Handle differences in interval constant formatting.
authorTom Hughes <tom@compton.nu>
Thu, 16 Apr 2009 20:47:18 +0000 (20:47 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 16 Apr 2009 20:47:18 +0000 (20:47 +0000)
db/migrate/025_add_end_time_to_changesets.rb
lib/migrate.rb

index b87ce3fdebabcf12abd2d1a192eb36547b9f155b..4941b72b92fb4b5264bfe42d84b2189394608e14 100644 (file)
@@ -7,8 +7,8 @@ class AddEndTimeToChangesets < ActiveRecord::Migration
     # it appears that execute will only accept string arguments, so
     # this is an ugly, ugly hack to get some sort of mysql/postgres
     # independence. now i have to go wash my brain with bleach.
-    execute("update changesets set closed_at=(now()-'1 hour') where open=(1=0)")
-    execute("update changesets set closed_at=(now()+'1 hour') where open=(1=1)")
+    execute("update changesets set closed_at=(now()-#{interval_constant('1 hour')}) where open=(1=0)")
+    execute("update changesets set closed_at=(now()+#{interval_constant('1 hour')}) where open=(1=1)")
 
     # remove the open column as it is unnecessary now and denormalises 
     # the table.
index 488c6d3d2a36eb5a3d39521b055b974d79241704..392060b6015a8cdb34d5fcfa6172e8a215b05eb4 100644 (file)
@@ -98,6 +98,10 @@ module ActiveRecord
       def alter_primary_key(table_name, new_columns)
         execute("alter table #{table_name} drop primary key, add primary key (#{new_columns.join(',')})")
       end
+
+      def interval_constant(interval)
+        "'#{interval}'"
+      end
     end
 
     class PostgreSQLAdapter
@@ -150,6 +154,10 @@ module ActiveRecord
       def alter_primary_key(table_name, new_columns)
         execute "alter table #{table_name} drop constraint #{table_name}_pkey; alter table #{table_name} add primary key (#{new_columns.join(',')})"
       end
+
+      def interval_constant(interval)
+        "'#{interval}'::interval"
+      end
     end
   end
 end