/* This script is responsible to replace a test data upload script file with a dummy script file which does not contain any sql statements Usage: Place the following 5 lines in the environment.properties file for the environment to which you do not want to upload test data # Migration hooks used to prevent test data upload scripts from being executed for this environment hook_before_each_up=JavaScript:pre-process.js hook_after_each_up=JavaScript:post-process.js hook_before_each_down=JavaScript:pre-process.js hook_after_each_down=JavaScript:post-process.js Requirements: This script requires the corresponding post-process.js script and the dummy migration scrip 'empty_migration_script.sql' to be in the same hook folder where this script is located */ // name of the migration script var scriptName = hookContext.getChange().getFilename(); // regular expression pattern used to check if the script is a test data upload script var pattern = /_upload[_]*test[_]*data/i; if (pattern.test(scriptName) == false) { print("Do nothing. Reason: " + scriptName + " is not a test data upload script"); exit; } // the suffix is added to the migration script filename to identify the backup file var suffix = '.skip'; // path to the dummy migration script var dummyScriptPath = migrationPaths.getHookPath().toPath().resolve('empty_migration_script.sql'); // path to the migration script var scriptPath = migrationPaths.getScriptPath().toPath().resolve(scriptName); print('-Process script ' + scriptName); print('-->Backup to ' + scriptName + suffix); // create a backup of the original migration script java.nio.file.Files.move(scriptPath, migrationPaths.getScriptPath().toPath().resolve(scriptName + suffix)); print('-->Replace with dummy script'); // replace original migration script with a dummy script java.nio.file.Files.copy(dummyScriptPath, scriptPath);