A platform for community discussion. Free, open, simple.
DEV: Less hacky way of rolling back DB changes
Gerhard Schlager5e3fc31f2c13
diff --git a/lib/backup_restore/database_restorer.rb b/lib/backup_restore/database_restorer.rbindex 033f8758d13..1e2c65504ac 100644--- a/lib/backup_restore/database_restorer.rb+++ b/lib/backup_restore/database_restorer.rb@@ -91,10 +91,10 @@ module BackupRestoreenddef restore_dump_command- "#{sed_command} #{@db_dump_path} | #{psql_command} 2>&1"+ "#{sed_command} #{@db_dump_path} | #{self.class.psql_command} 2>&1"end- def psql_command+ def self.psql_commanddb_conf = BackupRestore.database_configurationpassword_argument = "PGPASSWORD='#{db_conf.password}'" if db_conf.password.present?diff --git a/spec/lib/backup_restore/database_restorer_spec.rb b/spec/lib/backup_restore/database_restorer_spec.rbindex e4c4d6cb13c..5f595522d94 100644--- a/spec/lib/backup_restore/database_restorer_spec.rb+++ b/spec/lib/backup_restore/database_restorer_spec.rb@@ -69,17 +69,8 @@ describe BackupRestore::DatabaseRestorer docontext "with real psql" doafter do- DB.exec <<~SQL- -- Drop table and execute a commit to make the drop stick,- -- otherwise rspec will rollback the drop at the end of each test.- -- The tests in this context do not change the DB, so this should be safe.- DROP TABLE IF EXISTS foo;- COMMIT;-- -- Start a new transaction in order to suppress the- -- "there is no transaction in progress" warnings from rspec.- BEGIN TRANSACTION;- SQL+ psql = BackupRestore::DatabaseRestorer.psql_command+ system("#{psql} -c 'DROP TABLE IF EXISTS foo'", [:out, :err] => File::NULL)enddef restore(filename, stub_migrate: true)