Skip to content

A free open source IT asset/license management system

Fix back in time migrations for very old restores or upgrades

snipe5983a4530f03
diff --git a/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php b/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php
index cd93694ae3..054d57c5a1 100644
--- a/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php
+++ b/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php
@@ -24,6 +24,16 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
}
});
+
+ // This is a back in time migration to fix restores from very old versions of Snipe-IT where
+ // companies were not soft-deletable. We will undo this in this migration
+ // after the eol_explicit stuff is done
+ Schema::table('companies', function (Blueprint $table) {
+ if (!Schema::hasColumn('companies', 'deleted_at')) {
+ $table->datetime('deleted_at')->default(false);
+ }
+ });
+
// Update the eol_explicit column with the value from asset_eol_date if it exists and is different from the calculated value
Asset::whereNotNull('asset_eol_date')->with('model')->chunkById(500, function ($assetsWithEolDates) {
foreach ($assetsWithEolDates as $asset) {
@@ -54,6 +64,14 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
->update([
'asset_eol_date' => $this->eolUpdateExpression(),
]);
+
+
+ Schema::table('companies', function (Blueprint $table) {
+ if (!Schema::hasColumn('companies', 'deleted_at')) {
+ $table->dropColumn('deleted_at');
+ }
+ });
+
}
/**