6 0002_remove_genbank_taxon_id.pl
10 this_script.pl [options]
14 -D <dbname> (mandatory)
17 -H <dbhost> (mandatory)
20 -p <script_executor_user> (mandatory)
21 username to run the script
23 -F force to run this script and don't stop it by
24 missing previous db_patches
26 Note: If the first time that you run this script, obviously
27 you have no previous dbversion row in the md_dbversion
28 table, so you need to force the execution of this script
33 no need for genbank_taxon_id column in the organism table anymore.
41 =head1 COPYRIGHT & LICENSE
43 Copyright 2010 Boyce Thompson Institute for Plant Research
45 This program is free software; you can redistribute it and/or modify
46 it under the same terms as Perl itself.
56 use CXGN
::DB
::InsertDBH
;
57 use CXGN
::Metadata
::Dbversion
; ### Module to interact with the metadata.md_dbversion table
60 ## Declaration of the parameters used to run the script
62 our ($opt_H, $opt_D, $opt_p, $opt_F, $opt_h);
65 ## If is used -h <help> or none parameters is detailed print pod
67 if (!$opt_H && !$opt_D && !$opt_p && !$opt_F && !$opt_h) {
68 print STDOUT
"No optionas passed. Printing help\n\n";
76 ## Declaration of the name of the script and the description
78 my $patch_name = '0002_remove_genbank_taxon.pl';
79 my $patch_descr = 'This script removes the genbank_taxon_id column from the public organism table.';
81 print STDOUT
"\n+--------------------------------------------------------------------------------------------------+\n";
82 print STDOUT
"Executing the patch:\n $patch_name.\n\nDescription:\n $patch_descr.\n\nExecuted by:\n $opt_p.";
83 print STDOUT
"\n+--------------------------------------------------------------------------------------------------+\n\n";
85 ## And the requeriments if you want not use all
87 my @previous_requested_patches = ( ## ADD HERE
90 ## Specify the mandatory parameters
92 if (!$opt_H || !$opt_D) {
93 print STDOUT
"\nMANDATORY PARAMETER ERROR: -D <db_name> or/and -H <db_host> parameters has not been specified for $patch_name.\n";
97 print STDOUT
"\nMANDATORY PARAMETER ERROR: -p <script_executor_user> parameter has not been specified for $patch_name.\n";
100 ## Create the $schema object for the db_version object
101 ## This should be replace for CXGN::DB::DBICFactory as soon as it can use CXGN::DB::InsertDBH
103 my $dbh = CXGN
::DB
::InsertDBH
->new(
110 print STDOUT
"\nCreating the Metadata Schema object.\n";
112 my $metadata_schema = CXGN
::Metadata
::Schema
->connect(
114 { on_connect_do
=> ['SET search_path TO metadata;'] },
117 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
119 ### Now it will check if you have runned this patch or the previous patches
121 my $dbversion = CXGN
::Metadata
::Dbversion
->new($metadata_schema)
122 ->complete_checking( {
123 patch_name
=> $patch_name,
124 patch_descr
=> $patch_descr,
125 prepatch_req
=> \
@previous_requested_patches,
131 ### CREATE AN METADATA OBJECT and a new metadata_id in the database for this data
133 my $metadata = CXGN
::Metadata
::Metadbdata
->new($metadata_schema, $opt_p);
135 ### Get a new metadata_id (if you are using store function you only need to supply $metadbdata object)
137 my $metadata_id = $metadata->store()
140 ### Now you can insert the data using different options:
142 ## 1- By sql queryes using $dbh->do(<<EOSQL); and detailing in the tag the queries
144 ## 2- Using objects with the store function
146 ## 3- Using DBIx::Class first level objects
149 ## In this case we will use the SQL tag
151 print STDERR
"\nExecuting the SQL commands.\n";
155 ALTER TABLE public.organism DROP COLUMN genbank_taxon_id;
160 ## Now it will add this new patch information to the md_version table. It did the dbversion object before and
161 ## set the patch_name and the patch_description, so it only need to store it.
164 $dbversion->store($metadata);
166 print STDOUT
"DONE!\n";