6 [ this script name ].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 remove the tigrtc tracking tables
35 =head1 COPYRIGHT & LICENSE
37 Copyright 2010 Boyce Thompson Institute for Plant Research
39 This program is free software; you can redistribute it and/or modify
40 it under the same terms as Perl itself.
48 use Bio
::Chado
::Schema
;
51 use CXGN
::DB
::InsertDBH
;
52 use CXGN
::Metadata
::Dbversion
; ### Module to interact with the metadata.md_dbversion table
55 ## Declaration of the parameters used to run the script
57 our ($opt_H, $opt_D, $opt_p, $opt_F, $opt_h);
60 ## If is used -h <help> or none parameters is detailed print pod
62 if (!$opt_H && !$opt_D && !$opt_p && !$opt_F && !$opt_h) {
63 print STDOUT
"No optionas passed. Printing help\n\n";
71 ## Declaration of the name of the script and the description
73 my $patch_name = '0001_load_tomato_gen_pubs.pl';
74 my $patch_descr = 'This script stores pubprop for the tomato genome publications. It assumes these are ALREADY STORED in the database. The best way to load first the publications is by using the web interface ';
76 print STDOUT
"\n+--------------------------------------------------------------------------------------------------+\n";
77 print STDOUT
"Executing the patch:\n $patch_name.\n\nDescription:\n $patch_descr.\n\nExecuted by:\n $opt_p.";
78 print STDOUT
"\n+--------------------------------------------------------------------------------------------------+\n\n";
80 ## And the requeriments if you want not use all
82 my @previous_requested_patches = ( ## ADD HERE
85 ## Specify the mandatory parameters
87 if (!$opt_H || !$opt_D) {
88 print STDOUT
"\nMANDATORY PARAMETER ERROR: -D <db_name> or/and -H <db_host> parameters has not been specified for $patch_name.\n";
92 print STDOUT
"\nMANDATORY PARAMETER ERROR: -p <script_executor_user> parameter has not been specified for $patch_name.\n";
95 ## Create the $schema object for the db_version object
96 ## This should be replace for CXGN::DB::DBICFactory as soon as it can use CXGN::DB::InsertDBH
98 my $db = CXGN
::DB
::InsertDBH
->new(
104 my $dbh = $db->get_actual_dbh();
106 print STDOUT
"\nCreating the Metadata Schema object.\n";
108 my $metadata_schema = CXGN
::Metadata
::Schema
->connect(
110 { on_connect_do
=> ['SET search_path TO metadata;'] },
113 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
115 ### Now it will check if you have runned this patch or the previous patches
117 my $dbversion = CXGN
::Metadata
::Dbversion
->new($metadata_schema)
118 ->complete_checking( {
119 patch_name
=> $patch_name,
120 patch_descr
=> $patch_descr,
121 prepatch_req
=> \
@previous_requested_patches,
127 ### CREATE AN METADATA OBJECT and a new metadata_id in the database for this data
129 my $metadata = CXGN
::Metadata
::Metadbdata
->new($metadata_schema, $opt_p);
131 ### Get a new metadata_id (if you are using store function you only need to supply $metadbdata object)
133 my $metadata_id = $metadata->store()
136 ### Now you can insert the data using different options:
138 ## 1- By sql queryes using $dbh->do(<<EOSQL); and detailing in the tag the queries
140 ## 2- Using objects with the store function
142 ## 3- Using DBIx::Class first level objects
145 ## In this case we will use the SQL tag
147 print STDERR
"\nExecuting the SQL commands.\n";
149 $db->do("drop table $_") for qw(
152 sgn.tigrtc_membership
155 ## Now it will add this new patch information to the md_version table. It did the dbversion object before and
156 ## set the patch_name and the patch_description, so it only need to store it.
158 $dbversion->store($metadata);
160 print STDOUT
"DONE!\n";