[#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:
@@ -1,3 +1,9 @@
|
|||||||
|
2.031003 - 2015-02-04
|
||||||
|
|
||||||
|
[BUG FIXES]
|
||||||
|
|
||||||
|
* [#199] Missing schema changes when user has no permissions on DB
|
||||||
|
|
||||||
2.031002 - 2015-02-04
|
2.031002 - 2015-02-04
|
||||||
|
|
||||||
[BUG FIXES]
|
[BUG FIXES]
|
||||||
|
|||||||
@@ -50,15 +50,20 @@ netdisco-db-deploy - Database deployment for Netdisco
|
|||||||
|
|
||||||
This script upgrades or initialises a Netdisco database schema.
|
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
|
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
|
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
|
name must match those configured in your environment YAML file (default
|
||||||
C<~/environments/deployment.yml>).
|
C<~/environments/deployment.yml>).
|
||||||
|
|
||||||
Simply run this script, which connects to the database and runs without user
|
If you wish to force the redeployment of all database configuration, pass the
|
||||||
interaction. If there's no Nedisco schema, it is deployed. If there's an
|
C<--reset> argument on the command line.
|
||||||
unversioned schema then versioning is added, and updates applied. Otherwise
|
|
||||||
only necessary updates are applied to an already versioned schema.
|
|
||||||
|
|
||||||
=head1 VERSIONS
|
=head1 VERSIONS
|
||||||
|
|
||||||
@@ -74,7 +79,11 @@ Version 2 is the "classic" Netdisco database schema as of Netdisco 1.1
|
|||||||
|
|
||||||
=item *
|
=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
|
=back
|
||||||
|
|
||||||
@@ -82,6 +91,15 @@ Version 5 (and onwards) adds patches for Netdisco 1.2
|
|||||||
|
|
||||||
my $schema = schema('netdisco');
|
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"
|
# installs the dbix_class_schema_versions table with version "1"
|
||||||
# which corresponds to an empty schema
|
# which corresponds to an empty schema
|
||||||
if (not $schema->get_db_version) {
|
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);
|
$schema->upgrade_single_step($i, $i + 1);
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$schema->_set_db_version({version => $i + 1});
|
warn "Error: $_"
|
||||||
}
|
if $_ !~ m/(does not exist|already exists)/;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces(
|
|||||||
);
|
);
|
||||||
|
|
||||||
our # try to hide from kwalitee
|
our # try to hide from kwalitee
|
||||||
$VERSION = 39; # schema version used for upgrades, keep as integer
|
$VERSION = 40; # schema version used for upgrades, keep as integer
|
||||||
|
|
||||||
use Path::Class;
|
use Path::Class;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE admin DROP CONSTRAINT IF EXISTS admin_pkey;
|
||||||
|
|
||||||
ALTER TABLE admin ADD PRIMARY KEY (job);
|
ALTER TABLE admin ADD PRIMARY KEY (job);
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
@@ -12,6 +12,4 @@
|
|||||||
|
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
DELETE n1.* FROM node n1 INNER JOIN (SELECT mac, switch, port from node GROUP BY mac, switch, port HAVING count(*) > 1) n2 ON n1.mac = n2.mac AND n1.switch = n2.switch AND n1.port = n2.port AND n1.vlan = '0';
|
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
-- clean up node table where vlan = 0 and vlan = <another number>
|
||||||
|
--
|
||||||
|
-- DELETE n1.*
|
||||||
|
-- FROM node n1 INNER JOIN
|
||||||
|
-- (SELECT mac, switch, port from node
|
||||||
|
-- GROUP BY mac, switch, port
|
||||||
|
-- HAVING count(*) > 1) n2
|
||||||
|
-- ON n1.mac = n2.mac
|
||||||
|
-- AND n1.switch = n2.switch
|
||||||
|
-- AND n1.port = n2.port
|
||||||
|
-- AND n1.vlan = '0';
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DELETE FROM node AS n1 USING (SELECT mac, switch, port from node GROUP BY mac, switch, port HAVING count(*) > 1) n2 WHERE n1.mac = n2.mac AND n1.switch = n2.switch AND n1.port = n2.port AND n1.vlan = '0';
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -177,6 +177,13 @@ following commands into a shell script and call it nightly from C<cron>:
|
|||||||
This will keep 30 days of backups. You don't need to stop Netdisco during the
|
This will keep 30 days of backups. You don't need to stop Netdisco during the
|
||||||
backup.
|
backup.
|
||||||
|
|
||||||
|
=head1 Database Schema Redeployment
|
||||||
|
|
||||||
|
The database schema can be fully redeployed (even over an existing
|
||||||
|
installation, in a safe way) using the following command:
|
||||||
|
|
||||||
|
~netdisco/bin/netdisco-db-deploy --reset
|
||||||
|
|
||||||
=head1 Further Reading...
|
=head1 Further Reading...
|
||||||
|
|
||||||
Other ways to run and host the web application can be found in the
|
Other ways to run and host the web application can be found in the
|
||||||
|
|||||||
@@ -36,7 +36,25 @@ but they are backwards compatible.
|
|||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 2.031000
|
=head1 2.031003
|
||||||
|
|
||||||
|
=head2 Health Advice
|
||||||
|
|
||||||
|
This release will I<once again> remove from the database spurious Node
|
||||||
|
(workstation, printer, etc) entries on vlan 0, which were causing dupliate
|
||||||
|
entries in the web interface. We advise that you back up the database prior to
|
||||||
|
upgrade:
|
||||||
|
|
||||||
|
/usr/bin/pg_dump -F p --create -f netdisco-pgsql.dump netdisco
|
||||||
|
|
||||||
|
=head2 General Notices
|
||||||
|
|
||||||
|
=head1 2.031003
|
||||||
|
|
||||||
|
The database schema can be fully redeployed (even over an existing
|
||||||
|
installation, in a safe way) using the following command:
|
||||||
|
|
||||||
|
~netdisco/bin/netdisco-db-deploy --reset
|
||||||
|
|
||||||
=head2 General Notices
|
=head2 General Notices
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user