Sha256: c74056f245b3eee348ed6712b14f0b1fe5e0f09b9d943176b7e8409a83df04b2
Contents?: true
Size: 1.3 KB
Versions: 16
Compression:
Stored size: 1.3 KB
Contents
module SqlHelpers def without_transaction ActiveRecord::Base.connection.rollback_transaction yield ensure truncate_db end def truncate_db # Hit any tables that were used via active record ActiveRecord::Base.connection.tables.each do |table| ActiveRecord::Base.connection.execute("TRUNCATE #{table}") end # Just incase these models weren't loaded, do them explicitly ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::SubscriptionEvent.table_name}") ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::SelfServeSubscription.table_name}") end def replication_slots results = ActiveRecord::Base.connection.exec_query(<<~SQL) SELECT slot_name FROM pg_replication_slots SQL results.to_a.map { |result| result["slot_name"] } end def drop_replication_slot(slot_name) ActiveRecord::Base.connection.execute(<<~SQL) SELECT pg_drop_replication_slot('#{slot_name}') SQL end def wait_for_replication_slot(slot_name) wait_for do replication_slots.any? { |replication_slot| replication_slot == slot_name } end end def wait_for_replication_slot_cleanup(slot_name) wait_for do replication_slots.none? { |replication_slot| replication_slot == slot_name } end end end
Version data entries
16 entries across 16 versions & 1 rubygems