mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* 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:
@@ -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()
|
||||
});
|
||||
}
|
||||
}
|
@@ -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>";
|
||||
|
@@ -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: '' }
|
||||
|
Reference in New Issue
Block a user