schema update script

This commit is contained in:
Oliver Gorwits
2012-10-10 14:48:10 +01:00
parent 4b00105b1c
commit c2634a5dea
8 changed files with 106 additions and 85 deletions

View File

@@ -8,11 +8,25 @@ use Dancer::Plugin::DBIC 'schema';
use Netdisco::DB;
use Try::Tiny;
use feature 'say';
try {
my $count = schema->resultset('Device')->count();
}
catch {
# fresh install? deploy the Netdisco::DB schema
say 'Deploying Netdisco::DB schema...';
schema->txn_do(sub { schema->deploy() });
exec $0;
};
if (not schema->get_db_version()) {
# installs the dbix_class_schema_versions table with version "0"
schema->install("0");
say 'Installing DBIx::Class versioning to Netdisco::DB schema...';
schema->txn_do(sub { schema->install("1") });
exec $0;
}
# upgrades from whatever dbix_class_schema_versions says, to $VERSION
schema->upgrade();
say 'Upgrading Netdisco::DB schema...';
schema->txn_do(sub { schema->upgrade() });