remove alerts.
[sgn.git] / db / 00002 / AddUserRoles.pm
blobb5067b209e3c3cddfd8d32c43be658e795491383
1 package AddUserRoles;
3 use Moose;
4 use 5.010;
5 extends 'CXGN::Metadata::Dbpatch';
7 sub init_patch {
8 my $self=shift;
9 my $name = __PACKAGE__;
10 say "dbpatch name is $name";
11 my $description = 'Add User Roles';
12 my @previous_requested_patches = (); #ADD HERE
14 $self->name($name);
15 $self->description($description);
16 $self->prereq(\@previous_requested_patches);
20 sub patch {
21 my $self=shift;
23 print "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
25 print "\nExecuting the SQL commands.\n";
27 $self->dbh->do(<<EOSQL);
29 CREATE TABLE sgn_people.sp_roles (
30 sp_role_id serial primary key,
31 name varchar(20)
34 CREATE TABLE sgn_people.sp_person_roles (
35 sp_person_role_id serial primary key,
36 sp_person_id bigint references sgn_people.sp_person on delete cascade,
37 sp_role_id bigint references sgn_people.sp_roles on delete cascade
40 INSERT INTO sgn_people.sp_roles(name) VALUES ('curator');
41 INSERT INTO sgn_people.sp_roles(name) VALUES ('sequencer');
42 INSERT INTO sgn_people.sp_roles(name) VALUES ('submitter');
43 INSERT INTO sgn_people.sp_roles(name) VALUES ('user');
45 INSERT INTO sgn_people.sp_person_roles (sp_role_id, sp_person_id)
46 SELECT sp_role_id, sp_person_id
47 FROM sgn_people.sp_person
48 JOIN sgn_people.sp_roles ON (user_type=name);
50 GRANT select, update, insert, delete ON sgn_people.sp_roles to postgres, web_usr;
51 GRANT select, update, insert, delete ON sgn_people.sp_person_roles to postgres, web_usr;
53 GRANT select, update, usage ON sgn_people.sp_roles_sp_role_id_seq to postgres, web_usr;
55 GRANT select, update, usage ON sgn_people.sp_person_roles_sp_person_role_id_seq to postgres, web_usr;
57 EOSQL
59 say "You're done!";