Skip to content

Instantly share code, notes, and snippets.

@simonamor
Last active February 28, 2017 13:06
Show Gist options
  • Select an option

  • Save simonamor/ab42a1b2942122e717768f6dab125700 to your computer and use it in GitHub Desktop.

Select an option

Save simonamor/ab42a1b2942122e717768f6dab125700 to your computer and use it in GitHub Desktop.
auto-deploying a database schema from catalyst app
use DBIx::Class::DeploymentHandler;
# (removed standard Catalyst app module stuff)
# Start the application
__PACKAGE__->setup();
my $model = __PACKAGE__->model('DB');
my $dh = DBIx::Class::DeploymentHandler->new({
schema => $model->schema,
force_overwrite => 0,
script_directory => __PACKAGE__->path_to("ddl")->stringify,
databases => ['MySQL'],
});
if ($dh->version_storage_is_installed) {
if ($dh->next_version_set) {
warn "next version set is not undef - we should call upgrade()";
my $ret = eval {
$dh->upgrade();
};
die "upgrade failed: $@\n" if $@;
} else {
warn "next version is undef - nothing to do";
}
} else {
warn "version storage is installed - we should call install()";
my $ret = eval {
$dh->install();
};
die "install failed: $@\n" if $@;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment