summaryrefslogtreecommitdiff
path: root/bin/pg-readonly
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pg-readonly')
-rw-r--r--bin/pg-readonly24
1 files changed, 24 insertions, 0 deletions
diff --git a/bin/pg-readonly b/bin/pg-readonly
new file mode 100644
index 0000000..ad69fbd
--- /dev/null
+++ b/bin/pg-readonly
@@ -0,0 +1,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();
+ }
+}