blob: ad69fbde295a2bca9ab2c5b0a49c3776ac2080ff (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 | #!/usr/bin/perl
#
# hack to update/add read-only permissions for a user on the db
#
# usage: pg-readonly freesideuser readonlyuser
use strict;
use DBI;
use FS::UID qw(adminsuidsetup);
use FS::Record qw(dbdef);
my $user = shift or die &usage;
my $rouser = shift or die &usage;
my $dbh = adminsuidsetup $user;
foreach my $table ( dbdef->tables ) {
  $dbh->do("GRANT SELECT ON $table TO $rouser");
  $dbh->commit();
  if ( my $pkey = dbdef->table($table)->primary_key ) {
    $dbh->do("GRANT SELECT ON ${table}_${pkey}_seq TO $rouser");
    $dbh->commit();
  }
}
 |