Skip to content

Commit

Permalink
[tools] 20.0 tools and SQL moved to proper directory (aces#3855)
Browse files Browse the repository at this point in the history
This moves

the Normalize_protocol_split_rows.php to the proper directory and updates its relative references
the SQL output on Normalize_Consent_Data.php to the archive directory directly to avoid uncommitted code in the production environment's Cleanup_patches directory.
  • Loading branch information
ridz1208 authored Aug 3, 2018
1 parent d6a00ae commit f9d79ba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ htdocs/js/components/.module-cache/
node_modules/
modules/*/js/*.map
htdocs/js/components/*.map
npm-debug.log*
npm-debug.log*
SQL/Archive/autogenerated/reversion/*.sql
SQL/Archive/autogenerated/single_use/*.sql
SQL/Archive/autogenerated/*.sql
5 changes: 5 additions & 0 deletions SQL/Archive/autogenerated/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This directory contains SQL patches automatically generated from scripts in the
tools directory.

**Note:** SQL patches should not be generated directly into this directory;
they should be added to one of the subdirectories it contains.
9 changes: 9 additions & 0 deletions SQL/Archive/autogenerated/reversion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This directory contains SQL patches automatically generated to revert database changes
applied in a tool script. Patches in this directory are designed to roll-back the
database into a previous state and should only be run by project administrators after
thorough testing.

**Notes:**
- It is left to the author of the tool script to decide if a
roll-back behaviour is required.
- Files in this directory are not tracked by github.
5 changes: 5 additions & 0 deletions SQL/Archive/autogenerated/single_use/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This directory contains SQL patches automatically generated by tool scripts and
designed to be applied on the database only once; running these scripts more
than once might result in an SQL failure.

**Note:** Files in this directory are not tracked by github.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* This script imports existing consent data from `participant_status` and `consent_info_history` into new normalized tables.
*
* A SQL file is exported to path: loris_root/SQL/Cleanup_patches/delete_old_consent_tables.sql
* A SQL file is exported to path: loris_root/SQL/Archive/autogenerated/single_use/delete_old_consent_tables.sql
* after running this script. Source this file to delete the now deprecated tables and columns.
*
* affected tables:
Expand Down Expand Up @@ -144,7 +144,7 @@
$configID = $db->pselectOne("SELECT ID FROM ConfigSettings WHERE Name='useConsent'", array());
if (empty($configID)) {
array_push($errors, "useConsent missing from ConfigSettings table.
Run SQL/New_patches/2018-03-01_normalise_consent.sql");
Run SQL/Release_patches/19.1_To_20.0_upgrade.sql");
print_r($errors);
echo "\nResolve errors and run script again.\n";
die();
Expand All @@ -154,12 +154,12 @@
array('configid'=>$configID));
if (empty($configValue)) {
array_push($errors, "useConsent's Config value missing from Config table.
Run SQL/New_patches/2018-03-01_normalise_consent.sql");
Run SQL/Release_patches/19.1_To_20.0_upgrade.sql");
}
// Check new consent tables exist
if (!$db->tableExists('consent') || !$db->tableExists('candidate_consent_rel') || !$db->tableExists('candidate_consent_history')) {
array_push($errors, "New, normalized consent tables do not exist.
Run SQL/New_patches/2018-03-01_normalise_consent.sql");
Run SQL/Release_patches/19.1_To_20.0_upgrade.sql");
}
// Check rel and history tables are empty
$consentRelResult = $db->pselect("SELECT * FROM candidate_consent_rel", array());
Expand Down Expand Up @@ -300,6 +300,12 @@
'EntryDate' => $entryDate,
];
//Populate candidate_consent_history table
//Nullifying empty field to avoid data truncation
foreach ($formattedHistory as $k=>$v) {
if ($v === '') {
Utility::nullifyEmpty($formattedHistory,$k);
}
}
$db->insert('candidate_consent_history', $formattedHistory);
}
}
Expand All @@ -316,8 +322,8 @@
$columnName = $column['Column_name'];
$output .= "ALTER TABLE participant_status DROP COLUMN " . $columnName . ";\n";
}
$filename = __DIR__ . "/../../SQL/Cleanup_patches/delete_old_consent_tables.sql";

$filename = __DIR__ . "/../../SQL/Archive/autogenerated/single_use/delete_old_consent_tables.sql";
$fp = fopen($filename, "w");
fwrite($fp, $output);
fclose($fp);
?>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @link https://www.github.com/aces/Loris
*/

require_once 'generic_includes.php';
require_once __DIR__ . '/../generic_includes.php';
require_once 'Database.class.inc';
require_once 'Utility.class.inc';

Expand Down Expand Up @@ -80,6 +80,4 @@ function split_commas($table_name) {
$tables_to_normalize = array("mri_protocol", "mri_protocol_checks");
foreach ($tables_to_normalize as $table) {
split_commas($table);
}

?>
}

0 comments on commit f9d79ba

Please sign in to comment.