Skip to content

Commit 996f9d8

Browse files
authored
Merge branch 'develop' into Bugfix/DEVSU-2931-updated_by-is-not-getting-populated
2 parents 0456157 + e22105e commit 996f9d8

5 files changed

Lines changed: 109 additions & 15 deletions

File tree

app/models/reports/report.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,6 @@ module.exports = (sequelize, Sq) => {
7676
},
7777
allowNull: false,
7878
},
79-
seqQc: {
80-
name: 'seqQc',
81-
field: 'seq_qc',
82-
type: Sq.JSONB,
83-
jsonSchema: {
84-
schema: {
85-
type: 'array',
86-
items: {
87-
type: 'object',
88-
},
89-
example: [{Reads: '2534M', bioQC: 'passed'}],
90-
},
91-
},
92-
},
9379
config: {
9480
type: Sq.TEXT,
9581
},

app/models/reports/smallMutations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ module.exports = (sequelize, Sq) => {
134134
field: 'tumour_ref_copies',
135135
type: Sq.INTEGER,
136136
},
137+
exon: {
138+
type: Sq.TEXT,
139+
},
137140
library: {
138141
type: Sq.TEXT,
139142
},

app/routes/report/appendices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ router.route('/')
1313
try {
1414
const result = await db.models.report.findOne({
1515
where: {ident: req.report.ident},
16-
attributes: ['seqQc', 'config'],
16+
attributes: ['config'],
1717
include: ['seqQC'],
1818
});
1919
return res.json(result);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const TABLE = 'reports_small_mutations';
2+
3+
module.exports = {
4+
async up(queryInterface, Sequelize) {
5+
await queryInterface.addColumn(TABLE, 'exon', {
6+
type: Sequelize.TEXT,
7+
});
8+
},
9+
10+
async down(queryInterface) {
11+
await queryInterface.removeColumn(TABLE, 'exon');
12+
},
13+
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const {v4: uuidv4} = require('uuid');
2+
3+
module.exports = {
4+
up: async (queryInterface) => {
5+
await queryInterface.sequelize.transaction(async (transaction) => {
6+
const reports = await queryInterface.sequelize.query(
7+
`
8+
SELECT id, seq_qc
9+
FROM reports
10+
WHERE seq_qc IS NOT NULL;
11+
`,
12+
{
13+
type: queryInterface.sequelize.QueryTypes.SELECT,
14+
transaction,
15+
},
16+
);
17+
18+
const now = new Date();
19+
const rows = [];
20+
21+
for (const report of reports) {
22+
for (const seqQCItem of report.seq_qc) {
23+
rows.push({
24+
ident: uuidv4(),
25+
created_at: now,
26+
updated_at: now,
27+
report_id: report.id,
28+
reads: seqQCItem.Reads,
29+
bio_qc: seqQCItem.bioQC,
30+
lab_qc: seqQCItem.labQC,
31+
sample: seqQCItem.Sample,
32+
library: seqQCItem.Library,
33+
coverage: seqQCItem.Coverage,
34+
input_ng: seqQCItem.Input_ng,
35+
input_ug: seqQCItem.Input_ug,
36+
protocol: seqQCItem.Protocol,
37+
sample_name: seqQCItem['Sample Name'],
38+
duplicate_reads_perc: seqQCItem.Duplicate_Reads_Perc,
39+
});
40+
}
41+
}
42+
43+
if (rows.length !== 0) {
44+
await queryInterface.bulkInsert('reports_seqqc', rows, {transaction});
45+
}
46+
47+
await queryInterface.removeColumn('reports', 'seq_qc', {transaction});
48+
});
49+
},
50+
51+
down: async (queryInterface, Sq) => {
52+
await queryInterface.sequelize.transaction(async (transaction) => {
53+
await queryInterface.addColumn('reports', 'seq_qc', {
54+
type: Sq.JSONB,
55+
defaultValue: null,
56+
}, {transaction});
57+
58+
await queryInterface.sequelize.query(`
59+
WITH restored_seq_qc AS (
60+
SELECT
61+
report_id,
62+
jsonb_agg(jsonb_build_object(
63+
'Reads', reads,
64+
'bioQC', bio_qc,
65+
'labQC', lab_qc,
66+
'Sample', sample,
67+
'Library', library,
68+
'Coverage', coverage,
69+
'Input_ng', input_ng,
70+
'Input_ug', input_ug,
71+
'Protocol', protocol,
72+
'Sample Name', sample_name,
73+
'Duplicate_Reads_Perc', duplicate_reads_perc
74+
)) AS seq_qc
75+
FROM reports_seqqc
76+
GROUP BY report_id
77+
)
78+
UPDATE reports r
79+
SET seq_qc = restored_seq_qc.seq_qc
80+
FROM restored_seq_qc
81+
WHERE r.id = restored_seq_qc.report_id;
82+
`, {transaction});
83+
84+
await queryInterface.sequelize.query(`
85+
DELETE FROM reports_seqqc rs
86+
USING reports r
87+
WHERE rs.report_id = r.id
88+
AND r.seq_qc IS NOT NULL;
89+
`, {transaction});
90+
});
91+
},
92+
};

0 commit comments

Comments
 (0)