rename db management scripts

This commit is contained in:
Oliver Gorwits
2012-12-16 16:44:28 +00:00
parent 31f57cc71d
commit 369a235ff8
3 changed files with 45 additions and 39 deletions

View File

@@ -9,8 +9,24 @@ use Dancer::Plugin::DBIC 'schema';
use Netdisco::DB;
use Getopt::Long;
=head1 create_netdisco_schema_version
This script creates SQL DDL files of the Netdisco database schema.
If called without any CLI options, it makes one SQL DDL file which will
initialize the complete schema to the current DBIx::Class specification.
If called with the "-p <version>" option, upgrade SQL DDL command files
are created between the specified version and the current DBIx::Class
specification.
=cut
schema('netdisco')->create_ddl_dir(
'PostgreSQL', $version, $sql_dir, $preversion );
my $sql_dir = $Netdisco::DB::schema_versions_dir;
my $version = schema->schema_version();
my $version = schema('netdisco')->schema_version;
my ( $preversion, $help );
GetOptions(
@@ -33,18 +49,3 @@ $sql_dir
ENDHELP
exit(1);
};
schema->create_ddl_dir( 'PostgreSQL', $version, $sql_dir, $preversion );
=head1 create_netdisco_schema_version
This script creates SQL DDL files of the Netdisco database schema.
If called without any CLI options, it makes one SQL DDL file which will
initialize the complete schema to the current DBIx::Class specification.
If called with the "-p <version>" option, upgrade SQL DDL command files
are created between the specified version and the current DBIx::Class
specification.
=cut

View File

@@ -7,27 +7,6 @@ use Dancer ':script';
use Dancer::Plugin::DBIC 'schema';
use Try::Tiny;
use feature 'say';
if (not schema->get_db_version()) {
# installs the dbix_class_schema_versions table with version "1"
# which corresponds to an empty schema
say 'Installing DBIx::Class versioning to Netdisco::DB schema...';
schema->txn_do(sub { schema->install("1") });
exec $0;
}
try {
# if schema exists, assume it's current public Netdisco version
if (schema->get_db_version() == 1
and my $count = schema->resultset('Device')->count()) {
schema->txn_do(sub { schema->_set_db_version("2") });
}
};
# upgrades from whatever dbix_class_schema_versions says, to $VERSION
say 'Upgrading Netdisco::DB schema...';
schema->txn_do(sub { schema->upgrade() });
=head1 upgrade_netdisco_schema_version
@@ -66,3 +45,29 @@ Version 4 (not yet created) B<will diverge from "classic" Netdisco 1.x>
=back
=cut
my $schema = schema('netdisco');
# installs the dbix_class_schema_versions table with version "1"
# which corresponds to an empty schema
if (not $schema->get_db_version) {
$schema->txn_do(sub { $schema->install(1) });
$schema->storage->disconnect;
}
# test for existing schema at public release version, set v=2 if so
try {
$schema->storage->dbh_do(sub {
my ($storage, $dbh) = @_;
$dbh->selectrow_arrayref("SELECT * FROM device WHERE 0 = 1");
});
$schema->_set_db_version(2)
if $schema->get_db_version == 1;
$schema->storage->disconnect;
};
# upgrade from whatever dbix_class_schema_versions says, to $VERSION
$schema->txn_do(sub { $schema->upgrade });
exit 0;

View File

@@ -20,11 +20,11 @@ sub worker_begin {
$dbh->selectrow_arrayref("SELECT * FROM admin WHERE 0 = 1");
});
}
catch { $daemon->deploy };
catch { $daemon->txn_do( $daemon->deploy ) };
$daemon->storage->disconnect;
if ($daemon->get_db_version < $daemon->schema_version) {
$daemon->upgrade;
$daemon->txn_do( $daemon->upgrade );
}
# on start, any jobs previously grabbed by a daemon on this host