Skip to content

Commit

Permalink
Fixes for dbicdh.
Browse files Browse the repository at this point in the history
Closes #38

fixes and doc changes

consistent punctuation
  • Loading branch information
jberger committed Oct 13, 2014
1 parent 7ef516e commit f3b3d8a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 40 deletions.
14 changes: 13 additions & 1 deletion lib/Galileo.pm
Expand Up @@ -292,7 +292,19 @@ Warning: As usual, proper care should be taken when upgrading a database. This m
Although L<Galileo> does not need to be configured, it is recommended to do so to set your application's secret. The secret can be any string, however stronger is better. You do not need to memorize it or even remember it. This secret protects the cookies employed by Galileo from being tampered with on the client side.
Note that the database deployment tools may emit debugging information unexpectedly to your terminal, especially messages about "overwriting" and some internal "peek" information. These message are harmless, but as yet cannot be suppressed.
Notes:
=over
=item *
The database deployment tools may emit debugging information unexpectedly to your terminal, especially messages about "overwriting" and some internal "peek" information. These message are harmless, but as yet cannot be suppressed.
=item *
Upgrading database schemas from before Galileo version 0.012 (when schema versioning was introduced) is no longer supported as of version 0.037. The process wasn't testable anyway.
=back
=head3 dump
Expand Down
52 changes: 27 additions & 25 deletions lib/Galileo/Command/setup.pm
Expand Up @@ -7,26 +7,17 @@ use Mojolicious::Routes;
use Mojo::JSON 'j';
use Mojo::Util 'spurt';

use Galileo::DB::Deploy;

has description => "Configure your Galileo CMS via a web interface\n";

sub run {
my ($self, @args) = @_;

my $app = $self->app;
$app->plugin('Galileo::Plugin::Deploy'); # provides dh helper

my $r = Mojolicious::Routes->new;
$app->routes($r); # remove all routes

push @{ $app->renderer->classes }, __PACKAGE__;

$app->helper( dh => sub {
my $self = shift;
state $dh = Galileo::DB::Deploy->new( schema => $self->app->schema );
$dh;
});

$app->helper( 'control_group' => sub {
my $self = shift;
my $contents = pop;
Expand Down Expand Up @@ -63,24 +54,22 @@ sub run {
my $self = shift;

my $dh = $self->dh;
my $schema = $dh->schema;

my $available = $schema->schema_version;

# Nothing installed
unless ( $dh->has_admin_user ) {
my $installed = $dh->installed_version;
unless ( $installed ) {
return $self->render( 'setup/database' );
}

# Something is installed, check for a version
my $installed = $dh->installed_version || $dh->setup_unversioned;
# Something is installed, check for upgrades
my $available = $dh->schema->schema_version;

# Do nothing if version is current
if ( $installed == $available ) {
$self->flash( 'galileo.message' => 'Database schema is current' );
$self->flash( 'galileo.message' => 'Database schema is current.' );
} else {
$self->flash( 'galileo.message' => "Upgrade database $installed -> $available" );
$dh->do_upgrade;
$self->flash( 'galileo.message' => "Upgrade database $installed -> $available." );
}

$self->redirect_to('finish');
Expand All @@ -95,30 +84,43 @@ sub run {
return $self->redirect_to('database');
}

my $dh = $self->dh;
my $user = $self->param('user');
my $full = $self->param('full');

eval { $dh->schema->deploy };
eval { $dh->do_install };
eval { $dh->inject_sample_data($user, $pw1, $full) };
my $dh = $self->dh;

eval {
$dh->do_install;
$dh->inject_sample_data($user, $pw1, $full);
};

if ($@) {
my $error = "$@";
chomp $error;
$self->humane_flash( $error );
return $self->redirect_to('database');
}

$self->flash( 'galileo.message' => 'Database has been setup' );
$self->flash( 'galileo.message' => 'Database has been setup.' );
$self->redirect_to('finish');
});

$r->any('/finish' => sub {
my $self = shift;
my $message = $self->flash( 'galileo.message' );

# check that an admin user exists
if ( $self->app->dh->has_admin_user ) {
my $dh = $self->dh;
my $installed = $dh->installed_version;
my $available = $dh->schema->schema_version;
my $has_admin = $dh->has_admin_user;

if ($installed) {
unless ($has_admin) {
$message .= ' No administration user was created.';
}
unless ($installed == $available) {
$message .= " Installed database version ($installed) is older than the newest available ($available).";
}
$self->stash( 'galileo.success' => 1 );
$self->stash( 'galileo.message' => $message );
} else {
Expand Down
15 changes: 1 addition & 14 deletions lib/Galileo/DB/Deploy.pm
Expand Up @@ -67,24 +67,11 @@ sub installed_version {
return eval{ $self->database_version }
}

sub setup_unversioned {
my $self = shift;

unless ( $self->version_storage_is_installed ) {
$self->prepare_version_storage_install;
$self->install_version_storage;
}

$self->add_database_version({ version => 1 });

return 1;
}

sub do_install {
my $self = shift;

$self->prepare_install;
$self->install;
$self->install( @_ ? {version => shift} : () );
}

sub do_upgrade {
Expand Down
17 changes: 17 additions & 0 deletions lib/Galileo/Plugin/Deploy.pm
@@ -0,0 +1,17 @@
package Galileo::Plugin::Deploy;

use Mojo::Base 'Mojolicious::Plugin';

use Galileo::DB::Deploy;

sub register {
my ($plugin, $app) = @_;

my $dh = Galileo::DB::Deploy->new( schema => $app->schema );
$app->helper( dh => sub { $dh } );

return $dh;
}

1;

0 comments on commit f3b3d8a

Please sign in to comment.