Merge pull request #2783 from solgenomics/topic/fix_genotype_protocol_lookup
[sgn.git] / db / 00011 / AddMarkerExpAccession.pm
blobce73b42997a692a9f136e56b5e867cd64a1cc76b
1 #!/usr/bin/env perl
4 =head1 NAME
6 SampleDbpatchMoose.pm
8 =head1 SYNOPSIS
10 mx-run ThisPackageName [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.
15 =head1 DESCRIPTION
17 This is a test dummy patch.
18 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
20 =head1 AUTHOR
22 Naama Menda<nm249@cornell.edu>
24 =head1 COPYRIGHT & LICENSE
26 Copyright 2010 Boyce Thompson Institute for Plant Research
28 This program is free software; you can redistribute it and/or modify
29 it under the same terms as Perl itself.
31 =cut
34 package AddMarkerExpAccession;
36 use Moose;
37 extends 'CXGN::Metadata::Dbpatch';
40 sub init_patch {
41 my $self=shift;
42 my $name = __PACKAGE__;
43 print "dbpatch name is ':" . $name . "\n\n";
44 my $description = 'Adds a stock_id column to pcr_exp_accession and populates it.';
45 my @previous_requested_patches = (); #ADD HERE
47 $self->name($name);
48 $self->description($description);
49 $self->prereq(\@previous_requested_patches);
53 sub patch {
54 my $self=shift;
57 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
59 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
63 print STDOUT "\nExecuting the SQL commands.\n";
65 $self->dbh->do(<<EOSQL);
66 --do your SQL here
68 -- add a stock_id column to pcr_exp_accession
70 set search_path=public,sgn;
72 alter table sgn.pcr_exp_accession add column stock_id bigint references public.stock;
74 -- copy the stock to accession mapping from sgn.accession
76 update sgn.pcr_exp_accession set stock_id=sgn.accession.stock_id FROM sgn.accession where sgn.accession.accession_id=pcr_exp_accession.accession_id;
78 alter table sgn.map add column parent1_stock_id bigint references public.stock;
80 alter table sgn.map add column parent2_stock_id bigint references public.stock;
82 alter table sgn.map add column population_stock_id bigint references public.stock;
84 update sgn.map set parent1_stock_id=accession.stock_id FROM sgn.accession where sgn.accession.accession_id=map.parent_1;
86 update sgn.map set parent2_stock_id=accession.stock_id FROM sgn.accession where sgn.accession.accession_id=map.parent_2;
88 update sgn.map set population_stock_id=phenome.population.stock_id FROM phenome.population WHERE sgn.map.population_id=phenome.population.population_id;
90 -- remove trigger
91 drop trigger pcr_accession_check_trigger on sgn.pcr_exp_accession;;
93 alter table sgn.pcr_exp_accession drop constraint accession_id_check;
95 EOSQL
97 print "You're done!\n";
102 ####
103 1; #
104 ####