Class: RealDataTests::LoadStrategies::Psql

Inherits:
Base
  • Object
show all
Defined in:
lib/real_data_tests/load_strategies/psql.rb

Overview

Loads a SQL dump by shelling out to psql. The psql subprocess uses its own Postgres connection, so the loaded data commits immediately and does NOT participate in the caller's transaction (a transaction is per-connection; a child process can never join it).

This is the default strategy of load_real_test_data. Prefer the Native strategy (load_real_test_data_native) unless the dump requires psql itself — e.g. psql meta-commands (\set, \connect) or dumps too large to read into memory.

Instance Method Summary collapse

Methods inherited from Base

call

Instance Method Details

#call(dump_path) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
# File 'lib/real_data_tests/load_strategies/psql.rb', line 15

def call(dump_path)
  # Load the SQL dump quietly. Invoked without a shell (argv array +
  # :in redirect), so paths and connection values need no escaping.
  # Note: no transaction or session_replication_role handling here —
  # psql runs on its own Postgres session, so nothing set on the
  # ActiveRecord connection can affect the load.
  result = system('psql', *connection_args, in: dump_path)
  raise Error, "Failed to load test data: #{dump_path}" unless result
end