diff --git a/database/migrations/2023_01_21_225350_add_eol_date_on_assets_table.php b/database/migrations/2023_01_21_225350_add_eol_date_on_assets_table.php new file mode 100644 index 0000000000..95c3bff35b --- /dev/null +++ b/database/migrations/2023_01_21_225350_add_eol_date_on_assets_table.php @@ -0,0 +1,54 @@ +date('asset_eol_date')->after('purchase_date')->nullable()->default(null); + } + }); + + // Chunk the model query to get the models that do have an EOL date + AssetModel::whereNotNull('eol')->with('assets')->chunk(200, function ($models) { + foreach ($models as $model) { + foreach ($model->assets as $asset) { + + if ($asset->purchase_date!='') { + $asset->asset_eol_date = $asset->present()->eol_date(); + $asset->save(); + } + + } + } + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('assets', function (Blueprint $table) { + if (Schema::hasColumn('assets', 'asset_eol_date')) { + $table->dropColumn('asset_eol_date'); + } + }); + } +}