5 UpdatePhenotypeJsonbTableMaterializedViewWithNotes.pm
9 mx-run UpdatePhenotypeJsonbTableMaterializedViewWithNotes [options] -H hostname -D dbname -u username [-F]
11 this is a subclass of L<CXGN::Metadata::Dbpatch>
12 see the perldoc of parent class for more details.
16 This patch add the new phenotype operator and collect_date info into the materialized_phenotype_jsonb_table view.
22 =head1 COPYRIGHT & LICENSE
24 Copyright 2010 Boyce Thompson Institute for Plant Research
26 This program is free software; you can redistribute it and/or modify
27 it under the same terms as Perl itself.
32 package UpdatePhenotypeJsonbTableMaterializedViewWithNotes
;
35 use SGN
::Model
::Cvterm
;
36 use Bio
::Chado
::Schema
;
37 extends
'CXGN::Metadata::Dbpatch';
40 has
'+description' => ( default => <<'' );
41 This patch creates
/updates a materialized view
for phenotypes
in the traditional table format
.
46 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
48 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
50 print STDOUT
"\nExecuting the SQL commands.\n";
52 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
54 my $rep_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'replicate', 'stock_property')->cvterm_id();
55 my $block_number_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'block', 'stock_property')->cvterm_id();
56 my $plot_number_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot number', 'stock_property')->cvterm_id();
57 my $plant_number_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plant_index_number', 'stock_property')->cvterm_id();
58 my $row_number_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'row_number', 'stock_property')->cvterm_id();
59 my $col_number_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'col_number', 'stock_property')->cvterm_id();
60 my $is_a_control_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'is a control', 'stock_property')->cvterm_id();
61 my $notes_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'notes', 'stock_property')->cvterm_id();
62 my $year_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'project year', 'project_property')->cvterm_id();
63 my $design_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'design', 'project_property')->cvterm_id();
64 my $planting_date_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'project_planting_date', 'project_property')->cvterm_id();
65 my $havest_date_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'project_harvest_date', 'project_property')->cvterm_id();
66 my $project_location_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'project location', 'project_property')->cvterm_id();
67 my $plot_width_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot_width', 'project_property')->cvterm_id();
68 my $plot_length_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot_length', 'project_property')->cvterm_id();
69 my $field_size_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_size', 'project_property')->cvterm_id();
70 my $field_trial_is_planned_to_be_genotyped_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_trial_is_planned_to_be_genotyped', 'project_property')->cvterm_id();
71 my $field_trial_is_planned_to_cross_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_trial_is_planned_to_cross', 'project_property')->cvterm_id();
72 my $plot_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot', 'stock_type')->cvterm_id();
73 my $plant_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plant', 'stock_type')->cvterm_id();
74 my $subplot_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'subplot', 'stock_type')->cvterm_id();
75 my $accession_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'accession', 'stock_type')->cvterm_id();
76 my $phenotype_outlier_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'phenotype_outlier', 'phenotype_property')->cvterm_id();
77 my $breeding_program_rel_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'breeding_program_trial_relationship', 'project_relationship')->cvterm_id();
78 my $treatment_rel_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'trial_treatment_relationship', 'project_relationship')->cvterm_id();
79 my $folder_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'trial_folder', 'project_property')->cvterm_id();
80 my $field_layout_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'field_layout', 'experiment_type')->cvterm_id();
81 my $genotyping_layout_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'genotyping_layout', 'experiment_type')->cvterm_id();
82 my $phenotyping_experiment_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'phenotyping_experiment', 'experiment_type')->cvterm_id();
83 my $seedlot_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'seedlot', 'stock_type')->cvterm_id();
84 my $seedlot_transaction_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'seed transaction', 'stock_relationship')->cvterm_id();
85 my $seedlot_collection_of_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'collection_of', 'stock_relationship')->cvterm_id();
86 my $current_count_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'current_count', 'stock_property')->cvterm_id();
87 my $current_weight_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'current_weight_gram', 'stock_property')->cvterm_id();
88 my $seedlot_box_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'location_code', 'stock_property')->cvterm_id();
90 my $q = "SELECT observationunit.stock_id AS observationunit_stock_id, observationunit.uniquename AS observationunit_uniquename, observationunit_cvterm.name AS observationunit_type_name, germplasm.uniquename AS germplasm_uniquename, germplasm.stock_id AS germplasm_stock_id, rep.value AS rep, block_number.value AS block, plot_number.value AS plot_number, row_number.value AS row_number, col_number.value AS col_number, plant_number.value AS plant_number, is_a_control.value AS is_a_control, string_agg(distinct(notes.value), ', ') AS notes, project.project_id AS trial_id, project.name AS trial_name, project.description AS trial_description, plot_width.value AS plot_width, plot_length.value AS plot_length, field_size.value AS field_size, field_trial_is_planned_to_be_genotyped.value AS field_trial_is_planned_to_be_genotyped, field_trial_is_planned_to_cross.value AS field_trial_is_planned_to_cross, breeding_program.project_id AS breeding_program_id, breeding_program.name AS breeding_program_name, breeding_program.description AS breeding_program_description, year.value AS year, design.value AS design, location_id.value AS location_id, planting_date.value AS planting_date, harvest_date.value AS harvest_date, folder.project_id AS folder_id, folder.name AS folder_name, folder.description AS folder_description, seedplot_planted.value AS seedlot_transaction, seedlot.stock_id AS seedlot_stock_id, seedlot.uniquename AS seedlot_uniquename, seedlot_current_weight.value AS seedlot_current_weight_gram, seedlot_current_count.value AS seedlot_current_count, seedlot_seedlot_box.value AS seedlot_box_name, jsonb_object_agg(coalesce(case when (treatment.name) IS NULL then null else (treatment.name) end, 'No ManagementFactor'), treatment.description) AS treatments, COALESCE( jsonb_agg(jsonb_build_object('trait_id', phenotype.cvalue_id, 'trait_name', (((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text, 'value', phenotype.value, 'phenotype_id', phenotype.phenotype_id, 'outlier', outlier.value, 'create_date', phenotype.create_date, 'uniquename', phenotype.uniquename, 'phenotype_location_id', nd_geolocation.nd_geolocation_id, 'phenotype_location_name', nd_geolocation.description, 'collect_date', phenotype.collect_date, 'operator', phenotype.operator)) FILTER (WHERE phenotype.value IS NOT NULL), '[]' ) AS observations, COALESCE( jsonb_agg(jsonb_build_object('stock_id', available_seelot.stock_id, 'stock_uniquename', available_seelot.uniquename, 'current_weight_gram', current_weight.value, 'current_count', current_count.value, 'box_name', seedlot_box.value)) FILTER (WHERE available_seelot.stock_id IS NOT NULL), '[]' ) AS available_germplasm_seedlots FROM stock AS observationunit JOIN nd_experiment_stock ON(observationunit.stock_id=nd_experiment_stock.stock_id) JOIN nd_experiment USING(nd_experiment_id) JOIN nd_geolocation USING(nd_geolocation_id) LEFT JOIN stock_relationship AS seedplot_planted ON(seedplot_planted.subject_id = observationunit.stock_id AND seedplot_planted.type_id=$seedlot_transaction_type_id) LEFT JOIN stock AS seedlot ON(seedplot_planted.object_id = seedlot.stock_id AND seedlot.type_id=$seedlot_type_id) LEFT JOIN stockprop AS seedlot_current_count ON(seedlot.stock_id=seedlot_current_count.stock_id AND seedlot_current_count.type_id = $current_count_type_id) LEFT JOIN stockprop AS seedlot_current_weight ON(seedlot.stock_id=seedlot_current_weight.stock_id AND seedlot_current_weight.type_id = $current_weight_type_id) LEFT JOIN stockprop AS seedlot_seedlot_box ON(seedlot.stock_id=seedlot_seedlot_box.stock_id AND seedlot_seedlot_box.type_id = $seedlot_box_type_id) LEFT JOIN nd_experiment_phenotype USING(nd_experiment_id) LEFT JOIN phenotype USING(phenotype_id) JOIN cvterm AS observationunit_cvterm ON(observationunit.type_id=observationunit_cvterm.cvterm_id) JOIN stock_relationship ON(observationunit.stock_id=stock_relationship.subject_id) JOIN stock AS germplasm ON(stock_relationship.object_id=germplasm.stock_id AND germplasm.type_id = $accession_type_id) LEFT JOIN stock_relationship AS available_seedlot_rel ON (available_seedlot_rel.subject_id=germplasm.stock_id AND available_seedlot_rel.type_id=$seedlot_collection_of_type_id) LEFT JOIN stock AS available_seelot ON(available_seedlot_rel.object_id=available_seelot.stock_id AND seedlot.type_id=$seedlot_type_id) LEFT JOIN stockprop AS current_count ON(available_seelot.stock_id=current_count.stock_id AND current_count.type_id = $current_count_type_id) LEFT JOIN stockprop AS current_weight ON(available_seelot.stock_id=current_weight.stock_id AND current_weight.type_id = $current_weight_type_id) LEFT JOIN stockprop AS seedlot_box ON(available_seelot.stock_id=seedlot_box.stock_id AND seedlot_box.type_id = $seedlot_box_type_id) LEFT JOIN stockprop AS rep ON (observationunit.stock_id=rep.stock_id AND rep.type_id = $rep_type_id) LEFT JOIN stockprop AS block_number ON (observationunit.stock_id=block_number.stock_id AND block_number.type_id = $block_number_type_id) LEFT JOIN stockprop AS plot_number ON (observationunit.stock_id=plot_number.stock_id AND plot_number.type_id = $plot_number_type_id) LEFT JOIN stockprop AS row_number ON (observationunit.stock_id=row_number.stock_id AND row_number.type_id = $row_number_type_id) LEFT JOIN stockprop AS col_number ON (observationunit.stock_id=col_number.stock_id AND col_number.type_id = $col_number_type_id) LEFT JOIN stockprop AS plant_number ON (observationunit.stock_id=plant_number.stock_id AND plant_number.type_id = $plant_number_type_id) LEFT JOIN stockprop AS is_a_control ON (observationunit.stock_id=is_a_control.stock_id AND is_a_control.type_id = $is_a_control_type_id) LEFT JOIN stockprop AS notes ON (observationunit.stock_id=notes.stock_id AND notes.type_id = $notes_type_id) LEFT JOIN phenotypeprop AS outlier ON (phenotype.phenotype_id=outlier.phenotype_id AND outlier.type_id = $phenotype_outlier_type_id) LEFT JOIN cvterm ON (phenotype.cvalue_id=cvterm.cvterm_id) LEFT JOIN dbxref ON (cvterm.dbxref_id = dbxref.dbxref_id) LEFT JOIN db USING(db_id) JOIN nd_experiment_project USING(nd_experiment_id) JOIN project USING(project_id) JOIN project_relationship ON (project.project_id=project_relationship.subject_project_id AND project_relationship.type_id=$breeding_program_rel_type_id) JOIN project as breeding_program on (breeding_program.project_id=project_relationship.object_project_id) LEFT JOIN projectprop as year ON (project.project_id=year.project_id AND year.type_id = $year_type_id) LEFT JOIN projectprop as design ON (project.project_id=design.project_id AND design.type_id = $design_type_id) LEFT JOIN projectprop as location_id ON (project.project_id=location_id.project_id AND location_id.type_id = $project_location_type_id) LEFT JOIN projectprop as planting_date ON (project.project_id=planting_date.project_id AND planting_date.type_id = $planting_date_type_id) LEFT JOIN projectprop as harvest_date ON (project.project_id=harvest_date.project_id AND harvest_date.type_id = $havest_date_type_id) LEFT JOIN projectprop as plot_width ON (project.project_id=plot_width.project_id AND plot_width.type_id = $plot_width_type_id) LEFT JOIN projectprop as plot_length ON (project.project_id=plot_length.project_id AND plot_length.type_id = $plot_length_type_id) LEFT JOIN projectprop as field_size ON (project.project_id=field_size.project_id AND field_size.type_id = $field_size_type_id) LEFT JOIN projectprop as field_trial_is_planned_to_be_genotyped ON (project.project_id=field_trial_is_planned_to_be_genotyped.project_id AND field_trial_is_planned_to_be_genotyped.type_id = $field_trial_is_planned_to_be_genotyped_type_id) LEFT JOIN projectprop as field_trial_is_planned_to_cross ON (project.project_id=field_trial_is_planned_to_cross.project_id AND field_trial_is_planned_to_cross.type_id = $field_trial_is_planned_to_cross_type_id) LEFT JOIN project_relationship AS treatment_rel ON (project.project_id=treatment_rel.object_project_id AND treatment_rel.type_id = $treatment_rel_type_id) LEFT JOIN project AS treatment ON (treatment.project_id=treatment_rel.subject_project_id) LEFT JOIN project_relationship AS folder_rel ON (project.project_id=folder_rel.subject_project_id AND folder_rel.type_id = $folder_type_id) LEFT JOIN project AS folder ON (folder.project_id=folder_rel.object_project_id) WHERE nd_experiment.type_id IN ($field_layout_type_id, $genotyping_layout_type_id, $phenotyping_experiment_type_id) AND design.value != 'genotype_data_project' AND design.value != 'treatment' GROUP BY (observationunit.stock_id, observationunit.uniquename, observationunit_cvterm.name, germplasm.uniquename, germplasm.stock_id, rep.value, block_number.value, plot_number.value, row_number.value, col_number.value, plant_number.value, is_a_control.value, project.project_id, project.name, project.description, breeding_program.project_id, breeding_program.name, breeding_program.description, year.value, design.value, location_id.value, planting_date.value, harvest_date.value, plot_width.value, plot_length.value, field_size.value, field_trial_is_planned_to_be_genotyped.value, field_trial_is_planned_to_cross.value, folder.project_id, folder.name, folder.description, seedplot_planted.value, seedlot.stock_id, seedlot.uniquename, seedlot_current_weight.value, seedlot_current_count.value, seedlot_seedlot_box.value) ORDER by 14, 2;";
94 $self->dbh->do(<<EOSQL);
97 DROP MATERIALIZED VIEW IF EXISTS public.materialized_phenotype_jsonb_table CASCADE;
98 CREATE MATERIALIZED VIEW public.materialized_phenotype_jsonb_table AS
99 SELECT observationunit.stock_id AS observationunit_stock_id, observationunit.uniquename AS observationunit_uniquename, observationunit_cvterm.name AS observationunit_type_name, germplasm.uniquename AS germplasm_uniquename, germplasm.stock_id AS germplasm_stock_id, rep.value AS rep, block_number.value AS block, plot_number.value AS plot_number, row_number.value AS row_number, col_number.value AS col_number, plant_number.value AS plant_number, is_a_control.value AS is_a_control, string_agg(distinct(notes.value), ', ') AS notes, project.project_id AS trial_id, project.name AS trial_name, project.description AS trial_description, plot_width.value AS plot_width, plot_length.value AS plot_length, field_size.value AS field_size, field_trial_is_planned_to_be_genotyped.value AS field_trial_is_planned_to_be_genotyped, field_trial_is_planned_to_cross.value AS field_trial_is_planned_to_cross, breeding_program.project_id AS breeding_program_id, breeding_program.name AS breeding_program_name, breeding_program.description AS breeding_program_description, year.value AS year, design.value AS design, location_id.value AS location_id, planting_date.value AS planting_date, harvest_date.value AS harvest_date, folder.project_id AS folder_id, folder.name AS folder_name, folder.description AS folder_description, seedplot_planted.value AS seedlot_transaction, seedlot.stock_id AS seedlot_stock_id, seedlot.uniquename AS seedlot_uniquename, seedlot_current_weight.value AS seedlot_current_weight_gram, seedlot_current_count.value AS seedlot_current_count, seedlot_seedlot_box.value AS seedlot_box_name,
100 jsonb_object_agg(coalesce(
102 when (treatment.name) IS NULL then null
103 else (treatment.name)
105 'No ManagementFactor'), treatment.description) AS treatments,
107 jsonb_agg(jsonb_build_object('trait_id', phenotype.cvalue_id, 'trait_name', (((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text, 'value', phenotype.value, 'phenotype_id', phenotype.phenotype_id, 'outlier', outlier.value, 'create_date', phenotype.create_date, 'uniquename', phenotype.uniquename, 'phenotype_location_id', nd_geolocation.nd_geolocation_id, 'phenotype_location_name', nd_geolocation.description, 'collect_date', phenotype.collect_date, 'operator', phenotype.operator))
108 FILTER (WHERE phenotype.value IS NOT NULL), '[]'
111 jsonb_agg(jsonb_build_object('stock_id', available_seelot.stock_id, 'stock_uniquename', available_seelot.uniquename, 'current_weight_gram', current_weight.value, 'current_count', current_count.value, 'box_name', seedlot_box.value))
112 FILTER (WHERE available_seelot.stock_id IS NOT NULL), '[]'
113 ) AS available_germplasm_seedlots
114 FROM stock AS observationunit
115 JOIN nd_experiment_stock ON(observationunit.stock_id=nd_experiment_stock.stock_id)
116 JOIN nd_experiment USING(nd_experiment_id)
117 JOIN nd_geolocation USING(nd_geolocation_id)
118 LEFT JOIN stock_relationship AS seedplot_planted ON(seedplot_planted.subject_id = observationunit.stock_id AND seedplot_planted.type_id=$seedlot_transaction_type_id)
119 LEFT JOIN stock AS seedlot ON(seedplot_planted.object_id = seedlot.stock_id AND seedlot.type_id=$seedlot_type_id)
120 LEFT JOIN stockprop AS seedlot_current_count ON(seedlot.stock_id=seedlot_current_count.stock_id AND seedlot_current_count.type_id = $current_count_type_id)
121 LEFT JOIN stockprop AS seedlot_current_weight ON(seedlot.stock_id=seedlot_current_weight.stock_id AND seedlot_current_weight.type_id = $current_weight_type_id)
122 LEFT JOIN stockprop AS seedlot_seedlot_box ON(seedlot.stock_id=seedlot_seedlot_box.stock_id AND seedlot_seedlot_box.type_id = $seedlot_box_type_id)
123 LEFT JOIN nd_experiment_phenotype USING(nd_experiment_id)
124 LEFT JOIN phenotype USING(phenotype_id)
125 JOIN cvterm AS observationunit_cvterm ON(observationunit.type_id=observationunit_cvterm.cvterm_id)
126 JOIN stock_relationship ON(observationunit.stock_id=stock_relationship.subject_id)
127 JOIN stock AS germplasm ON(stock_relationship.object_id=germplasm.stock_id AND germplasm.type_id = $accession_type_id)
128 LEFT JOIN stock_relationship AS available_seedlot_rel ON (available_seedlot_rel.subject_id=germplasm.stock_id AND available_seedlot_rel.type_id=$seedlot_collection_of_type_id)
129 LEFT JOIN stock AS available_seelot ON(available_seedlot_rel.object_id=available_seelot.stock_id AND seedlot.type_id=$seedlot_type_id)
130 LEFT JOIN stockprop AS current_count ON(available_seelot.stock_id=current_count.stock_id AND current_count.type_id = $current_count_type_id)
131 LEFT JOIN stockprop AS current_weight ON(available_seelot.stock_id=current_weight.stock_id AND current_weight.type_id = $current_weight_type_id)
132 LEFT JOIN stockprop AS seedlot_box ON(available_seelot.stock_id=seedlot_box.stock_id AND seedlot_box.type_id = $seedlot_box_type_id)
133 LEFT JOIN stockprop AS rep ON (observationunit.stock_id=rep.stock_id AND rep.type_id = $rep_type_id)
134 LEFT JOIN stockprop AS block_number ON (observationunit.stock_id=block_number.stock_id AND block_number.type_id = $block_number_type_id)
135 LEFT JOIN stockprop AS plot_number ON (observationunit.stock_id=plot_number.stock_id AND plot_number.type_id = $plot_number_type_id)
136 LEFT JOIN stockprop AS row_number ON (observationunit.stock_id=row_number.stock_id AND row_number.type_id = $row_number_type_id)
137 LEFT JOIN stockprop AS col_number ON (observationunit.stock_id=col_number.stock_id AND col_number.type_id = $col_number_type_id)
138 LEFT JOIN stockprop AS plant_number ON (observationunit.stock_id=plant_number.stock_id AND plant_number.type_id = $plant_number_type_id)
139 LEFT JOIN stockprop AS is_a_control ON (observationunit.stock_id=is_a_control.stock_id AND is_a_control.type_id = $is_a_control_type_id)
140 LEFT JOIN stockprop AS notes ON (observationunit.stock_id=notes.stock_id AND notes.type_id = $notes_type_id)
141 LEFT JOIN phenotypeprop AS outlier ON (phenotype.phenotype_id=outlier.phenotype_id AND outlier.type_id = $phenotype_outlier_type_id)
142 LEFT JOIN cvterm ON (phenotype.cvalue_id=cvterm.cvterm_id)
143 LEFT JOIN dbxref ON (cvterm.dbxref_id = dbxref.dbxref_id)
144 LEFT JOIN db USING(db_id)
145 JOIN nd_experiment_project USING(nd_experiment_id)
146 JOIN project USING(project_id)
147 JOIN project_relationship ON (project.project_id=project_relationship.subject_project_id AND project_relationship.type_id=$breeding_program_rel_type_id)
148 JOIN project as breeding_program on (breeding_program.project_id=project_relationship.object_project_id)
149 LEFT JOIN projectprop as year ON (project.project_id=year.project_id AND year.type_id = $year_type_id)
150 LEFT JOIN projectprop as design ON (project.project_id=design.project_id AND design.type_id = $design_type_id)
151 LEFT JOIN projectprop as location_id ON (project.project_id=location_id.project_id AND location_id.type_id = $project_location_type_id)
152 LEFT JOIN projectprop as planting_date ON (project.project_id=planting_date.project_id AND planting_date.type_id = $planting_date_type_id)
153 LEFT JOIN projectprop as harvest_date ON (project.project_id=harvest_date.project_id AND harvest_date.type_id = $havest_date_type_id)
154 LEFT JOIN projectprop as plot_width ON (project.project_id=plot_width.project_id AND plot_width.type_id = $plot_width_type_id)
155 LEFT JOIN projectprop as plot_length ON (project.project_id=plot_length.project_id AND plot_length.type_id = $plot_length_type_id)
156 LEFT JOIN projectprop as field_size ON (project.project_id=field_size.project_id AND field_size.type_id = $field_size_type_id)
157 LEFT JOIN projectprop as field_trial_is_planned_to_be_genotyped ON (project.project_id=field_trial_is_planned_to_be_genotyped.project_id AND field_trial_is_planned_to_be_genotyped.type_id = $field_trial_is_planned_to_be_genotyped_type_id)
158 LEFT JOIN projectprop as field_trial_is_planned_to_cross ON (project.project_id=field_trial_is_planned_to_cross.project_id AND field_trial_is_planned_to_cross.type_id = $field_trial_is_planned_to_cross_type_id)
159 LEFT JOIN project_relationship AS treatment_rel ON (project.project_id=treatment_rel.object_project_id AND treatment_rel.type_id = $treatment_rel_type_id)
160 LEFT JOIN project AS treatment ON (treatment.project_id=treatment_rel.subject_project_id)
161 LEFT JOIN project_relationship AS folder_rel ON (project.project_id=folder_rel.subject_project_id AND folder_rel.type_id = $folder_type_id)
162 LEFT JOIN project AS folder ON (folder.project_id=folder_rel.object_project_id)
163 WHERE nd_experiment.type_id IN ($field_layout_type_id, $genotyping_layout_type_id, $phenotyping_experiment_type_id) AND design.value != 'genotype_data_project' AND design.value != 'treatment'
164 GROUP BY (observationunit.stock_id, observationunit.uniquename, observationunit_cvterm.name, germplasm.uniquename, germplasm.stock_id, rep.value, block_number.value, plot_number.value, row_number.value, col_number.value, plant_number.value, is_a_control.value, project.project_id, project.name, project.description, breeding_program.project_id, breeding_program.name, breeding_program.description, year.value, design.value, location_id.value, planting_date.value, harvest_date.value, plot_width.value, plot_length.value, field_size.value, field_trial_is_planned_to_be_genotyped.value, field_trial_is_planned_to_cross.value, folder.project_id, folder.name, folder.description, seedplot_planted.value, seedlot.stock_id, seedlot.uniquename, seedlot_current_weight.value, seedlot_current_count.value, seedlot_seedlot_box.value)
167 CREATE UNIQUE INDEX materialized_phenotype_jsonb_table_obsunit_stock_idx ON public.materialized_phenotype_jsonb_table(observationunit_stock_id) WITH (fillfactor=100);
168 CREATE INDEX materialized_phenotype_jsonb_table_obsunit_uniquename_idx ON public.materialized_phenotype_jsonb_table(observationunit_uniquename) WITH (fillfactor=100);
169 CREATE INDEX materialized_phenotype_jsonb_table_germplasm_stock_idx ON public.materialized_phenotype_jsonb_table(germplasm_stock_id) WITH (fillfactor=100);
170 CREATE INDEX materialized_phenotype_jsonb_table_germplasm_uniquename_idx ON public.materialized_phenotype_jsonb_table(germplasm_uniquename) WITH (fillfactor=100);
171 CREATE INDEX materialized_phenotype_jsonb_table_trial_idx ON public.materialized_phenotype_jsonb_table(trial_id) WITH (fillfactor=100);
172 CREATE INDEX materialized_phenotype_jsonb_table_trial_name_idx ON public.materialized_phenotype_jsonb_table(trial_name) WITH (fillfactor=100);
173 ALTER MATERIALIZED VIEW public.materialized_phenotype_jsonb_table OWNER TO web_usr;
175 CREATE OR REPLACE FUNCTION public.refresh_materialized_phenotype_jsonb_table() RETURNS VOID AS '
176 REFRESH MATERIALIZED VIEW public.materialized_phenotype_jsonb_table;'
179 ALTER FUNCTION public.refresh_materialized_phenotype_jsonb_table() OWNER TO web_usr;
181 CREATE OR REPLACE FUNCTION public.refresh_materialized_phenotype_jsonb_table_concurrently() RETURNS VOID AS '
182 REFRESH MATERIALIZED VIEW CONCURRENTLY public.materialized_phenotype_jsonb_table;'
185 ALTER FUNCTION public.refresh_materialized_phenotype_jsonb_table_concurrently() OWNER TO web_usr;
190 print "You're done!\n";