Skip to content

Commit 7fecc9e

Browse files
Merge pull request #578 from biocore/csymons_fix_cloned_barcode
Fix Cloned Barcode
2 parents b9f678e + c39c485 commit 7fecc9e

File tree

1 file changed

+68
-0
lines changed
  • microsetta_private_api/db/patches

1 file changed

+68
-0
lines changed
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
-- In 0139.sql, we cloned two samples into new barcodes. Unfortunately, one of the source barcodes provided was incorrect.
2+
-- This patch completely backs out the erroneous clone, then clones the correct sample.
3+
4+
-- First, we completely erase what we created for 0364406520
5+
DELETE FROM ag.vioscreen_registry vr
6+
USING ag.ag_kit_barcodes akb
7+
WHERE vr.sample_id = akb.ag_kit_barcode_id
8+
AND akb.barcode = '0364406520';
9+
10+
DELETE FROM barcodes.barcode_scans
11+
WHERE barcode = '0364406520';
12+
13+
DELETE FROM ag.source_barcodes_surveys
14+
WHERE barcode = '0364406520';
15+
16+
DELETE FROM ag.ag_kit_barcodes
17+
WHERE barcode = '0364406520';
18+
19+
DELETE FROM barcodes.project_barcode
20+
WHERE barcode = '0364406520';
21+
22+
DELETE FROM barcodes.barcode
23+
WHERE barcode = '0364406520';
24+
-- End erasing 0364406520
25+
26+
-- Now, we clone 000031037 into 0364406520
27+
INSERT INTO barcodes.barcode (barcode, assigned_on, status, sample_postmark_date, biomass_remaining, sequencing_status, obsolete, create_date_time, kit_id)
28+
SELECT '0364406520', assigned_on, status, sample_postmark_date, biomass_remaining, sequencing_status, obsolete, create_date_time, kit_id
29+
FROM barcodes.barcode
30+
WHERE barcode = '000031037';
31+
32+
INSERT INTO barcodes.project_barcode (project_id, barcode)
33+
SELECT project_id, '0364406520'
34+
FROM barcodes.project_barcode
35+
WHERE barcode = '000031037';
36+
37+
-- I'm omitting the sample_barcode_file and sample_barcode_file_md5 as they're
38+
-- no longer used and it would be inappropriate to directly clone a different
39+
-- barcode's associated file.
40+
INSERT INTO ag.ag_kit_barcodes (ag_kit_id, barcode, site_sampled, sample_date, sample_time, notes, moldy, overloaded, other, other_text, date_of_last_email, results_ready, withdrawn, refunded, deposited, source_id, latest_sample_information_update)
41+
SELECT ag_kit_id, '0364406520', site_sampled, sample_date, sample_time, notes, moldy, overloaded, other, other_text, date_of_last_email, results_ready, withdrawn, refunded, deposited, source_id, latest_sample_information_update
42+
FROM ag.ag_kit_barcodes
43+
WHERE barcode = '000031037';
44+
45+
INSERT INTO ag.source_barcodes_surveys (barcode, survey_id)
46+
SELECT '0364406520', survey_id
47+
FROM ag.source_barcodes_surveys
48+
WHERE barcode = '000031037';
49+
50+
INSERT INTO barcodes.barcode_scans (barcode, scan_timestamp, sample_status, technician_notes)
51+
SELECT '0364406520', scan_timestamp, sample_status, technician_notes
52+
FROM barcodes.barcode_scans
53+
WHERE barcode = '000031037';
54+
55+
INSERT INTO ag.vioscreen_registry (account_id, source_id, sample_id, vio_id, deleted, registration_code)
56+
WITH temp_1 AS (
57+
SELECT vr.account_id, vr.source_id, vr.vio_id, vr.deleted, vr.registration_code
58+
FROM ag.vioscreen_registry vr
59+
INNER JOIN ag.ag_kit_barcodes akb ON vr.sample_id = akb.ag_kit_barcode_id
60+
WHERE akb.barcode = '000031037'
61+
),
62+
temp_2 AS (
63+
SELECT ag_kit_barcode_id
64+
FROM ag.ag_kit_barcodes
65+
WHERE barcode = '0364406520'
66+
)
67+
SELECT temp_1.account_id, temp_1.source_id, temp_2.ag_kit_barcode_id, temp_1.vio_id, temp_1.deleted, temp_1.registration_code FROM temp_1, temp_2;
68+
-- End cloning 000031037 into 0364406520

0 commit comments

Comments
 (0)