set messed-up SGN::View::Feature test as TODO
[sgn.git] / db / 0002_remove_tigrtc_tables.pl
blob9e768f5685a1c619956a4106008b9f8aacc6ac0a
1 #!/usr/bin/env perl
4 =head1 NAME
6 [ this script name ].pl
8 =head1 SYNOPSIS
10 this_script.pl [options]
12 Options:
14 -D <dbname> (mandatory)
15 dbname to load into
17 -H <dbhost> (mandatory)
18 dbhost to load into
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
29 using -F
31 =head1 DESCRIPTION
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.
42 =cut
45 use strict;
46 use warnings;
48 use Bio::Chado::Schema;
49 use Pod::Usage;
50 use Getopt::Std;
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);
58 getopts("H:D:p:Fh");
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";
64 pod2usage(1);
66 elsif ($opt_h) {
67 pod2usage(1);
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
83 );
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";
91 if (!$opt_p) {
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(
100 dbname => $opt_D,
101 dbhost => $opt_H
104 my $dbh = $db->get_actual_dbh();
106 print STDOUT "\nCreating the Metadata Schema object.\n";
108 my $metadata_schema = CXGN::Metadata::Schema->connect(
109 sub { $dbh },
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,
122 force => $opt_F
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()
134 ->get_metadata_id();
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(
150 sgn.tigrtc_index
151 sgn.tigrtc_tracking
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";
162 $dbh->commit;
164 __END__