[#199] Missing schema changes when user has no permissions on DB

This fixes many glitches with the schema deployment:
- silently ignoring real failure modes such as user not having
correct permissions on the DB
- a couple of broken upgrade steps
- adds --reset so schema can be fully redeployed
This commit is contained in:
Oliver Gorwits
2015-02-04 21:43:44 +00:00
parent fe612df578
commit e99f5ee410
8 changed files with 78 additions and 11 deletions

View File

@@ -50,15 +50,20 @@ netdisco-db-deploy - Database deployment for Netdisco
This script upgrades or initialises a Netdisco database schema.
~netdisco/bin/netdisco-db-deploy [--reset]
This script connects to the database and runs without user interaction. If
there's no Nedisco schema, it is deployed. If there's an unversioned schema
then versioning is added, and updates applied. Otherwise only necessary
updates are applied to an already versioned schema.
Pre-existing requirements are that there be a database table created and a
user with rights to create tables in that database. Both the table and user
name must match those configured in your environment YAML file (default
C<~/environments/deployment.yml>).
Simply run this script, which connects to the database and runs without user
interaction. If there's no Nedisco schema, it is deployed. If there's an
unversioned schema then versioning is added, and updates applied. Otherwise
only necessary updates are applied to an already versioned schema.
If you wish to force the redeployment of all database configuration, pass the
C<--reset> argument on the command line.
=head1 VERSIONS
@@ -74,7 +79,11 @@ Version 2 is the "classic" Netdisco database schema as of Netdisco 1.1
=item *
Version 5 (and onwards) adds patches for Netdisco 1.2
Versions 5 to 16 add patches for Netdisco 1.2
=item *
Version 17 onwards deploys schema upgrades for Netdisco 2
=back
@@ -82,6 +91,15 @@ Version 5 (and onwards) adds patches for Netdisco 1.2
my $schema = schema('netdisco');
if (scalar @ARGV and $ARGV[0] and $ARGV[0] eq '--reset') {
$schema->storage->dbh_do(
sub {
my ($storage, $dbh, @args) = @_;
$dbh->do('DROP TABLE dbix_class_schema_versions');
},
);
}
# installs the dbix_class_schema_versions table with version "1"
# which corresponds to an empty schema
if (not $schema->get_db_version) {
@@ -112,8 +130,9 @@ for (my $i = $db_version; $i < $target_version; $i++) {
$schema->upgrade_single_step($i, $i + 1);
}
catch {
$schema->_set_db_version({version => $i + 1});
}
warn "Error: $_"
if $_ !~ m/(does not exist|already exists)/;
};
}
exit 0;