Merge pull request #2700 from solgenomics/derived_trait
[sgn.git] / db / 00043 / AddPublicListField.pm
blob6b3d7be71872a1a034907549638bf752abdb3c61
1 package AddPublicListField;
3 =head1 NAME
5 AddPublicListField
7 =head1 SYNOPSIS
9 Add is_public boolean field (NOT NULL DEAFULT FALSE) to sgn_people.list table
11 mx-run AddPublicListField [options] -H hostname -D dbname -u username [-F]
13 This is a subclass of L<CXGN::Metadata::Dbpatch>
15 =head1 DESCRIPTION
17 =head1 AUTHOR
19 Nick Morales
21 =head1 COPYRIGHT & LICENSE
23 Copyright 2010 Boyce Thompson Institute for Plant Research
25 This program is free software; you can redistribute it and/or modify
26 it under the same terms as Perl itself.
28 =cut
30 use Try::Tiny;
31 use Moose;
32 use 5.010;
33 extends 'CXGN::Metadata::Dbpatch';
35 sub init_patch {
36 my $self=shift;
37 my $name = __PACKAGE__;
38 say "dbpatch name $name";
39 my $description = 'Add is_public boolean field to sgn_people.list';
40 my @previous_requested_patches = ();
41 $self->name($name);
42 $self->description($description);
43 $self->prereq(\@previous_requested_patches);
46 sub patch {
47 my $self=shift;
48 say "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
49 say "Checking if this db_patch was executed before or if previous db_patches have been executed.\n";
50 say "Executing the SQL commands.\n";
52 my $sql = <<SQL;
53 ALTER TABLE sgn_people.list ADD COLUMN "is_public" BOOLEAN DEFAULT FALSE;
54 UPDATE sgn_people.list SET is_public = 'f';
55 ALTER TABLE sgn_people.list ALTER COLUMN is_public SET NOT NULL;
56 SQL
58 $self->dbh->do($sql);
59 say "Have a nice day!";