6 AddTimestampToNdTables.pm
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.
17 Adds a column called 'create_date' to the stock, project, genotype, phenotype, and nd_protocol tables. this column is set to DEFAULT NOW() when an entry is created. This is useful for creating reports of which project, stocks, phenotypes, etc were added over different time periods.
19 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
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.
34 package AddTimestampToNdTables
;
38 extends
'CXGN::Metadata::Dbpatch';
41 has
'+description' => ( default => <<'' );
42 Adds a column called
'create_date' to the nd_experiment
, stock
, project
, genotype
, phenotype
, and nd_protocol tables
. this column is set to DEFAULT NOW
() when an entry is created
. This is useful
for creating reports of which project
, stocks
, phenotypes
, etc were added over different
time periods
.
47 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
49 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
51 print STDOUT
"\nExecuting the SQL commands.\n";
55 $self->dbh->do(<<EOSQL);
56 ALTER TABLE nd_experiment ADD COLUMN create_date TIMESTAMP;
57 ALTER TABLE nd_experiment ALTER COLUMN create_date SET DEFAULT now();
61 print STDOUT
"nd_experiment already had create_date\n";
65 $self->dbh->do(<<EOSQL);
66 ALTER TABLE stock ADD COLUMN create_date TIMESTAMP;
67 ALTER TABLE stock ALTER COLUMN create_date SET DEFAULT now();
71 print STDOUT
"stock already had create_date\n";
75 $self->dbh->do(<<EOSQL);
76 ALTER TABLE project ADD COLUMN create_date TIMESTAMP;
77 ALTER TABLE project ALTER COLUMN create_date SET DEFAULT now();
81 print STDOUT
"project already had create_date\n";
85 $self->dbh->do(<<EOSQL);
86 ALTER TABLE phenotype ADD COLUMN create_date TIMESTAMP;
87 ALTER TABLE phenotype ALTER COLUMN create_date SET DEFAULT now();
91 print STDOUT
"phenotype already had create_date\n";
95 $self->dbh->do(<<EOSQL);
96 ALTER TABLE genotype ADD COLUMN create_date TIMESTAMP;
97 ALTER TABLE genotype ALTER COLUMN create_date SET DEFAULT now();
101 print STDOUT
"genotype already had create_date\n";
105 $self->dbh->do(<<EOSQL);
106 ALTER TABLE nd_protocol ADD COLUMN create_date TIMESTAMP;
107 ALTER TABLE nd_protocol ALTER COLUMN create_date SET DEFAULT now();
111 print STDOUT
"nd_protocol already had create_date\n";
115 $self->dbh->do(<<EOSQL);
116 ALTER TABLE stock_relationship ADD COLUMN create_date TIMESTAMP;
117 ALTER TABLE stock_relationship ALTER COLUMN create_date SET DEFAULT now();
121 print STDOUT
"stock_relationship already had create_date\n";
125 $self->dbh->do(<<EOSQL);
126 ALTER TABLE project_relationship ADD COLUMN create_date TIMESTAMP;
127 ALTER TABLE project_relationship ALTER COLUMN create_date SET DEFAULT now();
131 print STDOUT
"project_relationship already had create_date\n";
134 print "You're done!\n";