Merge pull request #5069 from solgenomics/topic/accession_upload_file
[sgn.git] / db / 00139 / CreateFeaturepropJSONTable.pm
blobcbef3c0c663a1bdb6738a2414757510c3972181d
1 #!/usr/bin/env perl
4 =head1 NAME
6 CreateFeaturepropJSONTable.pm
8 =head1 SYNOPSIS
10 mx-run CreateFeaturepropJSONTable [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.
15 =head1 DESCRIPTION
17 This patch creates the featureprop_json table used for storing sequence metadata as JSON objects
18 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
20 =head1 AUTHOR
23 =head1 COPYRIGHT & LICENSE
25 Copyright 2010 Boyce Thompson Institute for Plant Research
27 This program is free software; you can redistribute it and/or modify
28 it under the same terms as Perl itself.
30 =cut
33 package CreateFeaturepropJSONTable;
35 use Moose;
37 extends 'CXGN::Metadata::Dbpatch';
39 has '+description' => ( default => <<'');
40 This patch creates the featureprop_json table used for storing sequence metadata as JSON objects
43 has '+prereq' => (
44 default => sub {
45 [],
49 sub patch {
50 my $self=shift;
52 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
54 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
56 print STDOUT "\nExecuting the SQL commands.\n";
60 $self->dbh->do(<<EOSQL);
62 -- table definition
63 CREATE TABLE IF NOT EXISTS public.featureprop_json (
64 "featureprop_json_id" SERIAL PRIMARY KEY,
65 "feature_id" int8 REFERENCES feature,
66 "type_id" int8 REFERENCES cvterm,
67 "nd_protocol_id" int8 REFERENCES nd_protocol,
68 "start_pos" int8,
69 "end_pos" int8,
70 "json" jsonb
73 -- add indices
74 CREATE INDEX feaureprop_json_idx1 ON featureprop_json(feature_id);
75 CREATE INDEX feaureprop_json_idx2 ON featureprop_json(type_id);
76 CREATE INDEX feaureprop_json_idx3 ON featureprop_json(nd_protocol_id);
77 CREATE INDEX feaureprop_json_idx4 ON featureprop_json(start_pos);
78 CREATE INDEX feaureprop_json_idx5 ON featureprop_json(end_pos);
80 -- grant usage to web_usr
81 GRANT ALL on public.featureprop_json to web_usr;
82 GRANT USAGE ON public.featureprop_json_featureprop_json_id_seq to web_usr;
84 EOSQL
86 print "You're done!\n";
90 ####
91 1; #
92 ####