Skip to content

A free open source IT asset/license management system

WIP: Add last_checkin to assets table

Marcus Moore56fb45f1eafb
diff --git a/database/migrations/2023_08_17_202638_add_last_checkin_to_assets.php b/database/migrations/2023_08_17_202638_add_last_checkin_to_assets.php
new file mode 100644
index 0000000000..c00a9d5c7b
--- /dev/null
+++ b/database/migrations/2023_08_17_202638_add_last_checkin_to_assets.php
@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddLastCheckinToAssets extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('assets', function (Blueprint $table) {
+ $table->dateTime('last_checkin')->after('last_checkout')->nullable();
+ });
+
+ DB::statement(
+ "UPDATE " . DB::getTablePrefix() . "assets SET last_checkin=(SELECT MAX(" . DB::getTablePrefix() . "action_logs.action_date) FROM " . DB::getTablePrefix() . "action_logs WHERE item_type='App\\\Models\\\Asset' AND " . DB::getTablePrefix() . "action_logs.item_id=" . DB::getTablePrefix() . "assets.id AND " . DB::getTablePrefix() . "action_logs.action_type='checkin from'"
+ );
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('assets', function (Blueprint $table) {
+ $table->dropColumn('last_checkin');
+ });
+ }
+}