From 5021bac8641bc1eac15372d455a256123f98ae67 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 25 Feb 2005 22:07:57 +0000 Subject: adding quick pg-readonly tool --- bin/pg-readonly | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bin/pg-readonly (limited to 'bin/pg-readonly') diff --git a/bin/pg-readonly b/bin/pg-readonly new file mode 100644 index 000000000..4f6d7c380 --- /dev/null +++ b/bin/pg-readonly @@ -0,0 +1,22 @@ +#!/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(); + $dbh->do("GRANT SELECT ON ${table}_seq TO $rouser"); + $dbh->commit(); +} -- cgit v1.2.1 From 76f5008e4d5f6f5016f1c136f740f1f4b9c0b29c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 25 Feb 2005 22:14:41 +0000 Subject: try to set the sequences right for modern Pg --- bin/pg-readonly | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bin/pg-readonly') diff --git a/bin/pg-readonly b/bin/pg-readonly index 4f6d7c380..ad69fbde2 100644 --- a/bin/pg-readonly +++ b/bin/pg-readonly @@ -17,6 +17,8 @@ my $dbh = adminsuidsetup $user; foreach my $table ( dbdef->tables ) { $dbh->do("GRANT SELECT ON $table TO $rouser"); $dbh->commit(); - $dbh->do("GRANT SELECT ON ${table}_seq TO $rouser"); - $dbh->commit(); + if ( my $pkey = dbdef->table($table)->primary_key ) { + $dbh->do("GRANT SELECT ON ${table}_${pkey}_seq TO $rouser"); + $dbh->commit(); + } } -- cgit v1.2.1