Hide devices added for devices that existed before #11104 (#11107)

* Migrate devices.inserted to allow null values and set existng row values to null

* Hide Device Added for devices that existed before https://github.com/librenms/librenms/pull/11104

* Don't display any date that stats with a zero

* make schema match migration
This commit is contained in:
Joseph Tingiris
2020-02-06 06:44:04 -05:00
committed by GitHub
parent c380921d4b
commit 6285caba52
3 changed files with 38 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DeviceInsertedNull extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('devices', function (Blueprint $table) {
// inserted column will not default null to CURRENT_TIMESTAMP
\DB::statement("alter table `devices` change `inserted` `inserted` timestamp NULL default CURRENT_TIMESTAMP;");
\DB::statement("update `devices` set `inserted`=NULL;"); // set all existing (legacy) rows to null
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('devices', function (Blueprint $table) {
// inserted column will default null to CURRENT_TIMESTAMP
\DB::statement("alter table `devices` change `inserted` `inserted` timestamp default CURRENT_TIMESTAMP;");
\DB::statement("update `devices` set `inserted`=NULL"); // timestamp all existing (legacy) rows to now()
});
}
}

View File

@@ -100,7 +100,7 @@ if ($device['sysContact']) {
</div>';
}
if (!empty($device['inserted'])) {
if (!empty($device['inserted']) && preg_match("/^0/", $device['inserted']) == 0) {
$inserted_text = "Device Added";
$inserted = (Time::formatInterval(time() - strtotime($device['inserted'])) . " ago");
echo "<div class='row'><div class='col-sm-4'>$inserted_text</div><div class='col-sm-8' title='$inserted_text on " . $device['inserted'] . "'>$inserted</div></div>";

View File

@@ -451,7 +451,7 @@ dbSchema:
devices:
Columns:
- { Field: device_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
- { Field: inserted, Type: timestamp, 'Null': false, Extra: '', Default: CURRENT_TIMESTAMP }
- { Field: inserted, Type: timestamp, 'Null': true, Extra: '', Default: CURRENT_TIMESTAMP }
- { Field: hostname, Type: varchar(128), 'Null': false, Extra: '' }
- { Field: sysName, Type: varchar(128), 'Null': true, Extra: '' }
- { Field: ip, Type: varbinary(16), 'Null': true, Extra: '' }