6 FixOutOfSyncNdGeolocations
10 mx-run FixOutOfSyncNdGeolocations [options] -H hostname -D dbname -u username [-F]
12 this is a subclass of L<CXGN::Metadata::Dbpatch>
13 see the perldoc of parent class for more details.
16 This patch updates nd_experiment.nd_geolocation_ids that are out of sync with the location specified in linked projectprop.values
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
21 Bryan Ellerbrock<bje24@cornell.edu>
23 =head1 COPYRIGHT & LICENSE
25 Copyright 2010 Boyce Thompson Institute for Plant Research
27 This program is free software; you can redistribute it and/or modify
28 it under the same terms as Perl itself.
33 package FixOutOfSyncNdGeolocations
;
36 use Bio
::Chado
::Schema
;
38 use SGN
::Model
::Cvterm
;
42 extends
'CXGN::Metadata::Dbpatch';
45 has
'+description' => ( default => <<'' );
46 This patch updates nd_experiment
.nd_geolocation_ids that are out of sync with the location specified
in linked projectprop
.values
58 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
60 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
62 print STDOUT
"\nExecuting the SQL commands.\n";
64 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
65 my $project_location_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'project location', 'project_property')->cvterm_id();
67 my $query = "UPDATE nd_experiment
68 SET nd_geolocation_id = projectprop.value::int
69 FROM nd_experiment_project
71 nd_experiment_project.project_id = projectprop.project_id AND
72 projectprop.type_id = ?
74 WHERE nd_experiment_project.nd_experiment_id = nd_experiment.nd_experiment_id
75 AND nd_experiment_project.nd_experiment_id IN (
76 SELECT ne.nd_experiment_id
77 FROM nd_experiment_project nep
78 JOIN nd_experiment ne USING(nd_experiment_id)
80 SELECT ne.nd_experiment_id
82 JOIN projectprop pp ON(
83 p.project_id=pp.project_id AND
85 SELECT cvterm_id FROM cvterm WHERE name = 'project location'
88 JOIN nd_experiment_project nep ON(p.project_id = nep.project_id)
89 JOIN nd_experiment ne ON(
90 nep.nd_experiment_id = ne.nd_experiment_id AND
91 ne.nd_geolocation_id = pp.value::int
93 JOIN cvterm c ON(ne.type_id=c.cvterm_id)
96 # print STDERR Dumper $q;
97 my $h = $schema->storage->dbh()->prepare($query);
98 $h->execute($project_location_id);
100 print "You're done!\n";