From e65f7b84c884f79c3f65beae3e07189a65a8a067 Mon Sep 17 00:00:00 2001 From: nick n <39005454+inphobia@users.noreply.github.com> Date: Mon, 27 May 2019 13:39:07 +0200 Subject: [PATCH] dbic sync between actual db & our functions/docs (#595) --- MANIFEST | 2 +- META.json | 9 ++-- META.yml | 6 +-- bin/netdisco-db-deploy | 14 ++++--- lib/App/Netdisco/DB.pm | 2 +- lib/App/Netdisco/DB/Result/DevicePort.pm | 6 +-- .../DB/Result/DevicePortProperties.pm | 8 ++-- lib/App/Netdisco/DB/Result/DevicePortSsid.pm | 4 +- lib/App/Netdisco/DB/Result/DeviceRoute.pm | 42 ------------------- lib/App/Netdisco/DB/Result/NodeWireless.pm | 4 +- lib/App/Netdisco/DB/Result/Statistics.pm | 4 +- .../App-Netdisco-DB-57-58-PostgreSQL.sql | 14 +++++++ 12 files changed, 42 insertions(+), 73 deletions(-) delete mode 100644 lib/App/Netdisco/DB/Result/DeviceRoute.pm create mode 100644 share/schema_versions/App-Netdisco-DB-57-58-PostgreSQL.sql diff --git a/MANIFEST b/MANIFEST index 42186a08..566cb575 100644 --- a/MANIFEST +++ b/MANIFEST @@ -35,7 +35,6 @@ lib/App/Netdisco/DB/Result/DevicePortSsid.pm lib/App/Netdisco/DB/Result/DevicePortVlan.pm lib/App/Netdisco/DB/Result/DevicePortWireless.pm lib/App/Netdisco/DB/Result/DevicePower.pm -lib/App/Netdisco/DB/Result/DeviceRoute.pm lib/App/Netdisco/DB/Result/DeviceSkip.pm lib/App/Netdisco/DB/Result/DeviceVlan.pm lib/App/Netdisco/DB/Result/Log.pm @@ -371,6 +370,7 @@ share/schema_versions/App-Netdisco-DB-53-54-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-54-55-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-55-56-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-56-57-PostgreSQL.sql +share/schema_versions/App-Netdisco-DB-57-58-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-6-7-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-7-8-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-8-9-PostgreSQL.sql diff --git a/META.json b/META.json index 498e8886..9bbca8d9 100644 --- a/META.json +++ b/META.json @@ -142,7 +142,7 @@ }, "App::Netdisco::DB" : { "file" : "lib/App/Netdisco/DB.pm", - "version" : "57" + "version" : "58" }, "App::Netdisco::DB::ExplicitLocking" : { "file" : "lib/App/Netdisco/DB/ExplicitLocking.pm" @@ -186,9 +186,6 @@ "App::Netdisco::DB::Result::DevicePower" : { "file" : "lib/App/Netdisco/DB/Result/DevicePower.pm" }, - "App::Netdisco::DB::Result::DeviceRoute" : { - "file" : "lib/App/Netdisco/DB/Result/DeviceRoute.pm" - }, "App::Netdisco::DB::Result::DeviceSkip" : { "file" : "lib/App/Netdisco/DB/Result/DeviceSkip.pm" }, @@ -806,7 +803,7 @@ }, "homepage" : "http://netdisco.org/", "license" : [ - "http://opensource.org/licenses/bsd-license.php" + "http://opensource.org/licenses/BSD-3-Clause" ], "repository" : { "url" : "https://github.com/netdisco/netdisco" @@ -815,5 +812,5 @@ "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, "version" : "2.042008", - "x_serialization_backend" : "JSON::PP version 2.97001" + "x_serialization_backend" : "JSON::PP version 4.02" } diff --git a/META.yml b/META.yml index 540cb9cd..85b0b3ac 100644 --- a/META.yml +++ b/META.yml @@ -38,7 +38,7 @@ provides: file: lib/App/Netdisco/Configuration.pm App::Netdisco::DB: file: lib/App/Netdisco/DB.pm - version: '57' + version: '58' App::Netdisco::DB::ExplicitLocking: file: lib/App/Netdisco/DB/ExplicitLocking.pm App::Netdisco::DB::Result::Admin: @@ -67,8 +67,6 @@ provides: file: lib/App/Netdisco/DB/Result/DevicePortWireless.pm App::Netdisco::DB::Result::DevicePower: file: lib/App/Netdisco/DB/Result/DevicePower.pm - App::Netdisco::DB::Result::DeviceRoute: - file: lib/App/Netdisco/DB/Result/DeviceRoute.pm App::Netdisco::DB::Result::DeviceSkip: file: lib/App/Netdisco/DB/Result/DeviceSkip.pm App::Netdisco::DB::Result::DeviceVlan: @@ -557,7 +555,7 @@ resources: MailingList: https://lists.sourceforge.net/lists/listinfo/netdisco-users bugtracker: https://github.com/netdisco/netdisco/issues homepage: http://netdisco.org/ - license: http://opensource.org/licenses/bsd-license.php + license: http://opensource.org/licenses/BSD-3-Clause repository: https://github.com/netdisco/netdisco version: '2.042008' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/bin/netdisco-db-deploy b/bin/netdisco-db-deploy index 51d7e8ac..7be37f27 100755 --- a/bin/netdisco-db-deploy +++ b/bin/netdisco-db-deploy @@ -57,13 +57,17 @@ 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>). +Pre-existing requirements are that there's a working database connection and a +user with rights to create tables in that database. These settings are defined +in your environment YAML file (default C<~/environments/deployment.yml>). If you wish to force the redeployment of all database configuration, pass the -C<--redeploy-all> argument on the command line. +C<--redeploy-all> argument on the command line. This will reset your database +version so the database scripts will run again, but no data will be deleted +other than what's done via the upgrade scripts. + +For more database info see the +L. =head1 VERSIONS diff --git a/lib/App/Netdisco/DB.pm b/lib/App/Netdisco/DB.pm index e0461961..baa9bd21 100644 --- a/lib/App/Netdisco/DB.pm +++ b/lib/App/Netdisco/DB.pm @@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces( ); our # try to hide from kwalitee - $VERSION = 57; # schema version used for upgrades, keep as integer + $VERSION = 58; # schema version used for upgrades, keep as integer use Path::Class; use File::ShareDir 'dist_dir'; diff --git a/lib/App/Netdisco/DB/Result/DevicePort.pm b/lib/App/Netdisco/DB/Result/DevicePort.pm index 216cf869..f0a04994 100644 --- a/lib/App/Netdisco/DB/Result/DevicePort.pm +++ b/lib/App/Netdisco/DB/Result/DevicePort.pm @@ -56,13 +56,13 @@ __PACKAGE__->add_columns( "remote_id", { data_type => "text", is_nullable => 1 }, "is_master", - { data_type => "bool", is_nullable => 0, default_value => \"false" }, + { data_type => "boolean", is_nullable => 0, default_value => \"false" }, "slave_of", { data_type => "text", is_nullable => 1 }, "manual_topo", - { data_type => "bool", is_nullable => 0, default_value => \"false" }, + { data_type => "boolean", is_nullable => 0, default_value => \"false" }, "is_uplink", - { data_type => "bool", is_nullable => 1 }, + { data_type => "boolean", is_nullable => 1 }, "vlan", { data_type => "text", is_nullable => 1 }, "pvid", diff --git a/lib/App/Netdisco/DB/Result/DevicePortProperties.pm b/lib/App/Netdisco/DB/Result/DevicePortProperties.pm index b25fdaaf..deff2181 100644 --- a/lib/App/Netdisco/DB/Result/DevicePortProperties.pm +++ b/lib/App/Netdisco/DB/Result/DevicePortProperties.pm @@ -14,9 +14,9 @@ __PACKAGE__->add_columns( "error_disable_cause", { data_type => "text", is_nullable => 1 }, "remote_is_wap", - { data_type => "boolean", is_nullable => 1 }, + { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "remote_is_phone", - { data_type => "boolean", is_nullable => 1 }, + { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "remote_vendor", { data_type => "text", is_nullable => 1 }, "remote_model", @@ -26,9 +26,9 @@ __PACKAGE__->add_columns( "remote_serial", { data_type => "text", is_nullable => 1 }, "raw_speed", - { data_type => "bigint", is_nullable => 1 }, + { data_type => "bigint", default_value => 0, is_nullable => 1 }, "faststart", - { data_type => "boolean", is_nullable => 1 }, + { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "ifindex", { data_type => "bigint", is_nullable => 1 }, ); diff --git a/lib/App/Netdisco/DB/Result/DevicePortSsid.pm b/lib/App/Netdisco/DB/Result/DevicePortSsid.pm index 63e23856..ca113a4c 100644 --- a/lib/App/Netdisco/DB/Result/DevicePortSsid.pm +++ b/lib/App/Netdisco/DB/Result/DevicePortSsid.pm @@ -19,10 +19,10 @@ __PACKAGE__->add_columns( "broadcast", { data_type => "boolean", is_nullable => 1 }, "bssid", - { data_type => "macaddr", is_nullable => 1 }, + { data_type => "macaddr", is_nullable => 0 }, ); -__PACKAGE__->set_primary_key("port", "ip"); +__PACKAGE__->set_primary_key("ip", "bssid", "port"); # Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zvgylKzUQtizJZCe1rEdUg diff --git a/lib/App/Netdisco/DB/Result/DeviceRoute.pm b/lib/App/Netdisco/DB/Result/DeviceRoute.pm deleted file mode 100644 index 31e62457..00000000 --- a/lib/App/Netdisco/DB/Result/DeviceRoute.pm +++ /dev/null @@ -1,42 +0,0 @@ -use utf8; -package App::Netdisco::DB::Result::DeviceRoute; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; -__PACKAGE__->table("device_route"); -__PACKAGE__->add_columns( - "ip", - { data_type => "inet", is_nullable => 0 }, - "network", - { data_type => "cidr", is_nullable => 0 }, - "creation", - { - data_type => "timestamp", - default_value => \"current_timestamp", - is_nullable => 1, - original => { default_value => \"now()" }, - }, - "dest", - { data_type => "inet", is_nullable => 0 }, - "last_discover", - { - data_type => "timestamp", - default_value => \"current_timestamp", - is_nullable => 1, - original => { default_value => \"now()" }, - }, -); -__PACKAGE__->set_primary_key("ip", "network", "dest"); - - -# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3jcvPP60E5BvwnUbXql7mQ - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/lib/App/Netdisco/DB/Result/NodeWireless.pm b/lib/App/Netdisco/DB/Result/NodeWireless.pm index c2e8aad0..75a6133f 100644 --- a/lib/App/Netdisco/DB/Result/NodeWireless.pm +++ b/lib/App/Netdisco/DB/Result/NodeWireless.pm @@ -25,9 +25,9 @@ __PACKAGE__->add_columns( "sigqual", { data_type => "integer", is_nullable => 1 }, "rxpkt", - { data_type => "integer", is_nullable => 1 }, + { data_type => "bigint", is_nullable => 1 }, "txpkt", - { data_type => "integer", is_nullable => 1 }, + { data_type => "bigint", is_nullable => 1 }, "rxbyte", { data_type => "bigint", is_nullable => 1 }, "txbyte", diff --git a/lib/App/Netdisco/DB/Result/Statistics.pm b/lib/App/Netdisco/DB/Result/Statistics.pm index a288dcbe..41207d37 100644 --- a/lib/App/Netdisco/DB/Result/Statistics.pm +++ b/lib/App/Netdisco/DB/Result/Statistics.pm @@ -8,8 +8,7 @@ use base 'DBIx::Class::Core'; __PACKAGE__->table("statistics"); __PACKAGE__->add_columns( "day", - { data_type => "date", is_nullable => 0 }, - + { data_type => "date", default_value => \"CURRENT_DATE", is_nullable => 0 }, "device_count", { data_type => "integer", is_nullable => 0 }, "device_ip_count", @@ -28,7 +27,6 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 0 }, "node_active_count", { data_type => "integer", is_nullable => 0 }, - "netdisco_ver", { data_type => "text", is_nullable => 1 }, "snmpinfo_ver", diff --git a/share/schema_versions/App-Netdisco-DB-57-58-PostgreSQL.sql b/share/schema_versions/App-Netdisco-DB-57-58-PostgreSQL.sql new file mode 100644 index 00000000..a4adcedc --- /dev/null +++ b/share/schema_versions/App-Netdisco-DB-57-58-PostgreSQL.sql @@ -0,0 +1,14 @@ +BEGIN; + +alter table device_port_wireless alter column ip set not null; +alter table device_port_wireless alter column port set not null; +alter table device_port_wireless add constraint device_port_wireless_pkey primary key (ip, port); + +alter table device_port_ssid alter column ip set not null; +alter table device_port_ssid alter column port set not null; +alter table device_port_ssid alter column bssid set not null; +alter table device_port_ssid add constraint device_port_ssid_pkey primary key (ip, bssid, port); + + + +COMMIT;