Skip to content

Commit

Permalink
hotfix migration from last release
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Jul 10, 2024
1 parent 9ab92ae commit a011566
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions database/migrations/2024_07_10_094930_change_objects_to_uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
public function up(): void
{
Schema::table('training_object_attachments', function (Blueprint $table) {
// Add a new UUID column
$table->uuid('uuid')->first(); // Adding it as the first column for convenience
// Step 1: Add a new UUID column
$table->uuid('uuid')->first();
});

// Assuming all your rows have unique IDs and you can iterate through them
// Populate the new uuid column with UUIDs
// Step 2: Populate the new uuid column with UUIDs
DB::table('training_object_attachments')->get()->each(function ($item) {
DB::table('training_object_attachments')
->where('id', $item->id)
->update(['uuid' => \Illuminate\Support\Str::uuid()]);
});

// Step 3: Remove auto-increment from the 'id' column
Schema::table('training_object_attachments', function (Blueprint $table) {
$table->dropPrimary();
$table->dropPrimary(['id']); // Drop the primary key
$table->unsignedBigInteger('id')->autoIncrement(false)->change(); // Remove auto-increment
});

// Step 4: Drop the 'id' column
Schema::table('training_object_attachments', function (Blueprint $table) {
$table->dropColumn('id');
});

// Step 5 & 6: Rename 'uuid' column to 'id' and set it as the primary key
Schema::table('training_object_attachments', function (Blueprint $table) {
$table->renameColumn('uuid', 'id');
});

Schema::table('training_object_attachments', function (Blueprint $table) {
$table->primary('id');
});
}
Expand All @@ -48,4 +48,4 @@ public function down(): void
{
// Breaking change, but harmless as things continue to work
}
};
};

0 comments on commit a011566

Please sign in to comment.