Skip to content

Commit

Permalink
use ActiveRecord's connection time zone setting instead of stating it…
Browse files Browse the repository at this point in the history
… exlicitly in the queries
  • Loading branch information
DerGuteMoritz committed Dec 6, 2010
1 parent 47a8289 commit 9616fa5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/salesforce_sync/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SalesforceSync::Database

def initialize(options)
@options = DefaultOptions.merge(options)
ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.establish_connection(@options[:connection])
create_syncs_table(@options[:syncs_table]) unless db.table_exists? @options[:syncs_table]
end
Expand Down Expand Up @@ -64,12 +65,12 @@ def last_sync_for(object)
end

def insert_sync_timestamp(object, timestamp)
db.insert("INSERT INTO %s (object, timestamp, created_at) VALUES (%s, %s, statement_timestamp() AT TIME ZONE 'UTC')" %
db.insert("INSERT INTO %s (object, timestamp, created_at) VALUES (%s, %s, statement_timestamp())" %
[syncs_table, db.quote(object), db.quote(timestamp)])
end

def clean_syncs_table(days)
db.delete("DELETE FROM %s AS a WHERE created_at < (SELECT MAX(created_at) FROM %s WHERE object = a.object) AND created_at < statement_timestamp() AT TIME ZONE 'UTC' - interval '%i days'" %
db.delete("DELETE FROM %s AS a WHERE created_at < (SELECT MAX(created_at) FROM %s WHERE object = a.object) AND created_at < statement_timestamp() - interval '%i days'" %
[syncs_table, syncs_table, db.quote(days)])
end

Expand Down

0 comments on commit 9616fa5

Please sign in to comment.