Sha256: 1335f0f975322e0c1f4ae647c1e04cca5fb7158e623ff99a342ff4c484bef019

Contents?: true

Size: 1.01 KB

Versions: 21

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module PgEventstore
  module TestHelpers
    class << self
      def clean_up_db
        clean_up_data
        clean_up_partitions
      end

      def clean_up_partitions
        PgEventstore.connection.with do |conn|
          # Dropping parent partition also drops all child partitions
          conn.exec("select tablename from pg_tables where tablename like 'contexts_%'").each do |attrs|
            conn.exec("drop table #{attrs['tablename']}")
          end
        end
      end

      def clean_up_data
        tables_to_purge = PgEventstore.connection.with do |conn|
          conn.exec(<<~SQL)
            SELECT tablename 
            FROM pg_catalog.pg_tables 
            WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND tablename != 'migrations'
          SQL
        end.map { |attrs| attrs['tablename'] }
        tables_to_purge.each do |table_name|
          PgEventstore.connection.with { |c| c.exec("DELETE FROM #{table_name}") }
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pg_eventstore-1.7.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.6.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.5.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.4.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.3.4 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.3.3 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.3.2 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.3.1 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.3.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.2.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.1.5 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.1.4 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.1.3 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.1.2 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.1.1 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.1.0 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.0.4 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.0.0.rc2 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-1.0.0.rc1 lib/pg_eventstore/rspec/test_helpers.rb
pg_eventstore-0.10.2 lib/pg_eventstore/rspec/test_helpers.rb