diff --git a/Web/lib/WeightGrapher/Web/Command/db_dump.pm b/Web/lib/WeightGrapher/Web/Command/db_dump.pm new file mode 100644 index 0000000..7f27cb2 --- /dev/null +++ b/Web/lib/WeightGrapher/Web/Command/db_dump.pm @@ -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; diff --git a/Web/lib/WeightGrapher/Web/Command/dbc.pm b/Web/lib/WeightGrapher/Web/Command/dbc.pm new file mode 100644 index 0000000..aa23860 --- /dev/null +++ b/Web/lib/WeightGrapher/Web/Command/dbc.pm @@ -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; diff --git a/Web/lib/WeightGrapher/Web/Command/flip_admin.pm b/Web/lib/WeightGrapher/Web/Command/flip_admin.pm new file mode 100644 index 0000000..7bdbbe8 --- /dev/null +++ b/Web/lib/WeightGrapher/Web/Command/flip_admin.pm @@ -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;