Skip to content

Commit

Permalink
[Hot fix] Reinstate entity answers for C19 test registration responses (
Browse files Browse the repository at this point in the history
  • Loading branch information
edmofro authored May 15, 2022
1 parent fe3f3f2 commit 98b2073
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

import { codeToId } from '../utilities';

var dbm;
var type;
var seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};

const SURVEY_CODE = 'C19T_Registration';
const QUESTION_CODE = 'C19T007';

exports.up = async function (db) {
// the missing entity answers have been stored as the parent of the primary entity of each
// response, copy the id from there into a new answer
const surveyId = await codeToId(db, 'survey', SURVEY_CODE);
const questionId = await codeToId(db, 'question', QUESTION_CODE);
await db.runSql(`
INSERT INTO answer (id, survey_response_id, question_id, type, text)
SELECT
generate_object_id(), survey_response.id, '${questionId}', 'Entity', entity.parent_id
FROM
survey_response
JOIN
entity
ON
survey_response.entity_id = entity.id
LEFT JOIN
answer
ON
answer.survey_response_id = survey_response.id and answer.question_id = '${questionId}'
WHERE
survey_id = '${surveyId}'
AND
answer.id is null;
`);
};

exports.down = function (db) {
return null;
};

exports._meta = {
version: 1,
};

0 comments on commit 98b2073

Please sign in to comment.