rename db management scripts
This commit is contained in:
@@ -9,8 +9,24 @@ use Dancer::Plugin::DBIC 'schema';
|
|||||||
use Netdisco::DB;
|
use Netdisco::DB;
|
||||||
use Getopt::Long;
|
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 $sql_dir = $Netdisco::DB::schema_versions_dir;
|
||||||
my $version = schema->schema_version();
|
my $version = schema('netdisco')->schema_version;
|
||||||
|
|
||||||
my ( $preversion, $help );
|
my ( $preversion, $help );
|
||||||
GetOptions(
|
GetOptions(
|
||||||
@@ -33,18 +49,3 @@ $sql_dir
|
|||||||
ENDHELP
|
ENDHELP
|
||||||
exit(1);
|
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
|
|
||||||
@@ -7,27 +7,6 @@ use Dancer ':script';
|
|||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
use Try::Tiny;
|
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
|
=head1 upgrade_netdisco_schema_version
|
||||||
|
|
||||||
@@ -66,3 +45,29 @@ Version 4 (not yet created) B<will diverge from "classic" Netdisco 1.x>
|
|||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=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;
|
||||||
@@ -20,11 +20,11 @@ sub worker_begin {
|
|||||||
$dbh->selectrow_arrayref("SELECT * FROM admin WHERE 0 = 1");
|
$dbh->selectrow_arrayref("SELECT * FROM admin WHERE 0 = 1");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch { $daemon->deploy };
|
catch { $daemon->txn_do( $daemon->deploy ) };
|
||||||
|
|
||||||
$daemon->storage->disconnect;
|
$daemon->storage->disconnect;
|
||||||
if ($daemon->get_db_version < $daemon->schema_version) {
|
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
|
# on start, any jobs previously grabbed by a daemon on this host
|
||||||
|
|||||||
Reference in New Issue
Block a user