parent
03d540f3cb
commit
88bc991d1d
3 changed files with 91 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||||
|
package WeightGrapher::Web::Command::db_dump; |
||||||
|
use Mojo::Base 'Mojolicious::Command'; |
||||||
|
use DBIx::Class::Schema::Config; |
||||||
|
|
||||||
|
use Mojo::Util qw( getopt ); |
||||||
|
|
||||||
|
has description => 'Dump the weightgrapher database.'; |
||||||
|
has usage => "$0 dbc"; |
||||||
|
|
||||||
|
sub run { |
||||||
|
my ( $self, @args ) = @_; |
||||||
|
|
||||||
|
my $db_conf = DBIx::Class::Schema::Config->coerce_credentials_from_mojolike( |
||||||
|
DBIx::Class::Schema::Config->_make_connect_attrs( |
||||||
|
$self->app->config->{database}{weightgrapher} |
||||||
|
) |
||||||
|
); |
||||||
|
|
||||||
|
if ( $db_conf->{dsn} =~ /^dbi:Pg:dbname=([^;]+);host=([^;]+)$/ ) { |
||||||
|
$db_conf->{dbname} = $1; |
||||||
|
$db_conf->{hostname} = $2; |
||||||
|
} |
||||||
|
|
||||||
|
$ENV{PGPASSWORD} = $db_conf->{password}; |
||||||
|
exec 'pg_dump', '-h', $db_conf->{hostname}, '-U', $db_conf->{user}, $db_conf->{dbname}; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
1; |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
package WeightGrapher::Web::Command::dbc; |
||||||
|
use Mojo::Base 'Mojolicious::Command'; |
||||||
|
use DBIx::Class::Schema::Config; |
||||||
|
|
||||||
|
use Mojo::Util qw( getopt ); |
||||||
|
|
||||||
|
has description => 'Connect to the DB as if running psql.'; |
||||||
|
has usage => "$0 dbc"; |
||||||
|
|
||||||
|
|
||||||
|
sub run { |
||||||
|
my ( $self, @args ) = @_; |
||||||
|
|
||||||
|
my $db_conf = DBIx::Class::Schema::Config->coerce_credentials_from_mojolike( |
||||||
|
DBIx::Class::Schema::Config->_make_connect_attrs( |
||||||
|
$self->app->config->{database}{weightgrapher} |
||||||
|
) |
||||||
|
); |
||||||
|
|
||||||
|
if ( $db_conf->{dsn} =~ /^dbi:Pg:dbname=([^;]+);host=([^;]+)$/ ) { |
||||||
|
$db_conf->{dbname} = $1; |
||||||
|
$db_conf->{hostname} = $2; |
||||||
|
} |
||||||
|
|
||||||
|
$ENV{PGPASSWORD} = $db_conf->{password}; |
||||||
|
exec 'psql', '-h', $db_conf->{hostname}, '-U', $db_conf->{user}, $db_conf->{dbname}; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
1; |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
package WeightGrapher::Web::Command::flip_admin; |
||||||
|
use Mojo::Base 'Mojolicious::Command'; |
||||||
|
use DBIx::Class::Schema::Config; |
||||||
|
|
||||||
|
use Mojo::Util qw( getopt ); |
||||||
|
|
||||||
|
has description => "Flip a user's admin bit."; |
||||||
|
has usage => "$0 flip_admin email\@domain.comi\n"; |
||||||
|
|
||||||
|
sub run { |
||||||
|
my ( $self, $email ) = @_; |
||||||
|
|
||||||
|
die "Error: you must provide an email address.\n" |
||||||
|
unless $email; |
||||||
|
|
||||||
|
my $person = $self->app->db->person( { email => $email } ); |
||||||
|
|
||||||
|
die "Error: couldn't find anyone with the email $email?\n" |
||||||
|
unless $person; |
||||||
|
|
||||||
|
if ( $person->is_admin ) { |
||||||
|
$person->is_admin( 0 ); |
||||||
|
print "That account was previously an admin. Now it is not.\n"; |
||||||
|
} else { |
||||||
|
$person->is_admin( 1 ); |
||||||
|
print "$email is now an admin.\n"; |
||||||
|
} |
||||||
|
|
||||||
|
$person->update; |
||||||
|
} |
||||||
|
|
||||||
|
1; |
||||||
Loading…
Reference in new issue