Module: PgEventstore::TestHelpers

Defined in:
lib/pg_eventstore/rspec/test_helpers.rb

Class Method Summary collapse

Class Method Details

.clean_up_dataObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pg_eventstore/rspec/test_helpers.rb', line 20

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

.clean_up_dbObject



6
7
8
9
# File 'lib/pg_eventstore/rspec/test_helpers.rb', line 6

def clean_up_db
  clean_up_data
  clean_up_partitions
end

.clean_up_partitionsObject



11
12
13
14
15
16
17
18
# File 'lib/pg_eventstore/rspec/test_helpers.rb', line 11

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