Skip to content

Instantly share code, notes, and snippets.

@tcopeland
Last active June 6, 2019 21:44
Show Gist options
  • Save tcopeland/b42dfcc436f2cdf21186a0c3bfec2e58 to your computer and use it in GitHub Desktop.
Save tcopeland/b42dfcc436f2cdf21186a0c3bfec2e58 to your computer and use it in GitHub Desktop.
module MyTweak
def execute(sql, name=nil)
if caller.detect {|x| x =~ /20171010151334/ } && sql !~ /SHOW TIME ZONE/
puts sql
else
super
end
end
end
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
prepend MyTweak
end
require "#{Rails.root}/db/migrate/20171010151334_add_wing_count_to_jets"
AddWingCountToJets.new.change
# example usage:
$ sc
Loading development environment (Rails 5.1.4)
irb(main):001:0> module MyTweak
irb(main):002:1> def execute(sql, name=nil)
irb(main):003:2> if caller.detect {|x| x =~ /20171010151334/ } && sql !~ /SHOW TIME ZONE/
irb(main):004:3> puts sql
irb(main):005:3> else
irb(main):006:3* super
irb(main):007:3> end
irb(main):008:2> end
irb(main):009:1> end
=> :execute
irb(main):010:0> class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
irb(main):011:1> prepend MyTweak
irb(main):012:1> end
=> ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
irb(main):013:0> require "#{Rails.root}/db/migrate/20171010151334_add_wing_count_to_jets"
=> true
irb(main):014:0> AddWingCountToJets.new.change
-- add_column(:jets, :wing_count, :integer)
SET client_min_messages TO 'warning'
SET standard_conforming_strings = on
SET time zone 'UTC'
ALTER TABLE "jets" ADD "wing_count" integer
-> 0.0234s
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment