Last active
March 17, 2021 17:22
-
-
Save omad/1ae3463a123f37a9acf37213bebfde86 to your computer and use it in GitHub Desktop.
Revisions
-
omad revised this gist
Jul 30, 2019 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ -- -- Use with psql from the command line: -- -- psql -v product_name=<product-to-delete> -f delete_odc_product.sql -h <database-hostname> <dbname> -- -- @@ -23,6 +23,9 @@ -- Are there any datasets that are descendents of this product? -- If so, they will need to be removed first! set search_path = 'agdc'; select count(*) from dataset_source left join dataset d on dataset_source.source_dataset_ref = d.id -
omad revised this gist
Jul 16, 2019 . 1 changed file with 22 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,21 @@ -------------------------------------- -- SQL to Delete a Data Cube Product -------------------------------------- -- -- Use with psql from the command line: -- -- psql -v product_name=<product-to-delete> -f delete_odc_product.sql -- -- -- COUNT NUMBER OF DATASETS OF EACH TYPE (including archived) -- -- select -- count(*), -- t.name -- from dataset -- left join dataset_type t on dataset.dataset_type_ref = t.id -- group by t.name; -- -- CHECK FOR LINEAGE RECORDS @@ -23,7 +28,7 @@ from dataset_source left join dataset d on dataset_source.source_dataset_ref = d.id where d.dataset_type_ref = (select id from dataset_type where dataset_type.name = :'product_name'); -- Are there any lineage records which need deleting? -- These are the lineage history of the product we're deleting. @@ -32,15 +37,15 @@ from dataset_source left join dataset d on dataset_source.dataset_ref = d.id where d.dataset_type_ref = (select id from dataset_type where dataset_type.name = :'product_name'); -- -- DELETE LINEAGE RECORDS -- WITH datasets as (SELECT id FROM dataset where dataset.dataset_type_ref = (select id FROM dataset_type WHERE name = :'product_name')) DELETE FROM dataset_source USING datasets where dataset_source.dataset_ref = datasets.id; @@ -54,14 +59,14 @@ from dataset_location left join dataset d on dataset_location.dataset_ref = d.id where d.dataset_type_ref = (select id from dataset_type where dataset_type.name = :'product_name'); WITH datasets as (SELECT id FROM dataset where dataset.dataset_type_ref = (select id FROM dataset_type WHERE name = :'product_name')) select count(*) from dataset_location, datasets where dataset_location.dataset_ref = datasets.id; @@ -74,7 +79,7 @@ WITH datasets as (SELECT id FROM dataset where dataset.dataset_type_ref = (select id FROM dataset_type WHERE name = :'product_name')) DELETE FROM dataset_location USING datasets where dataset_location.dataset_ref = datasets.id; @@ -85,11 +90,11 @@ where dataset_location.dataset_ref = datasets.id; DELETE FROM dataset where dataset.dataset_type_ref = (select id from dataset_type where dataset_type.name = :'product_name'); -- -- FINALLY, DELETE THE PRODUCT -- DELETE FROM dataset_type where dataset_type.name = :'product_name'; -
omad revised this gist
Feb 11, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
omad created this gist
Feb 11, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ # Danger This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,95 @@ ------------------------------------------ -- Some SQL to Delete a Data Cube Product ------------------------------------------ -- -- COUNT NUMBER OF DATASETS OF EACH TYPE (including archived) -- select count(*), t.name from dataset left join dataset_type t on dataset.dataset_type_ref = t.id group by t.name; -- -- CHECK FOR LINEAGE RECORDS -- -- Are there any datasets that are descendents of this product? -- If so, they will need to be removed first! select count(*) from dataset_source left join dataset d on dataset_source.source_dataset_ref = d.id where d.dataset_type_ref = (select id from dataset_type where dataset_type.name = 'ls8_fc_albers_archived'); -- Are there any lineage records which need deleting? -- These are the lineage history of the product we're deleting. select count(*) from dataset_source left join dataset d on dataset_source.dataset_ref = d.id where d.dataset_type_ref = (select id from dataset_type where dataset_type.name = 'ls8_fc_albers_archived'); -- -- DELETE LINEAGE RECORDS -- WITH datasets as (SELECT id FROM dataset where dataset.dataset_type_ref = (select id FROM dataset_type WHERE name = 'ls8_fc_albers_archived')) DELETE FROM dataset_source USING datasets where dataset_source.dataset_ref = datasets.id; -- -- CHECK FOR LOCATION RECORDS -- select count(*) from dataset_location left join dataset d on dataset_location.dataset_ref = d.id where d.dataset_type_ref = (select id from dataset_type where dataset_type.name = 'ls8_fc_albers_archived'); WITH datasets as (SELECT id FROM dataset where dataset.dataset_type_ref = (select id FROM dataset_type WHERE name = 'ls8_fc_albers_archived')) select count(*) from dataset_location, datasets where dataset_location.dataset_ref = datasets.id; -- -- DELETE LOCATION RECORDS -- WITH datasets as (SELECT id FROM dataset where dataset.dataset_type_ref = (select id FROM dataset_type WHERE name = 'ls8_fc_albers_archived')) DELETE FROM dataset_location USING datasets where dataset_location.dataset_ref = datasets.id; -- -- DELETE DATASET RECORDS -- DELETE FROM dataset where dataset.dataset_type_ref = (select id from dataset_type where dataset_type.name = 'ls8_fc_albers_archived'); -- -- FINALLY, DELETE THE PRODUCT -- DELETE FROM dataset_type where dataset_type.name = 'ls8_fc_albers_archived';