fix: add UUID support to CloudProviderToken model
- Add uuid column to cloud_provider_tokens table via migration - Update CloudProviderToken to extend BaseModel for auto UUID generation - Generate UUIDs for existing records in migration - Fixes null uuid issue in API responses 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ef0a1241b0
commit
10003cec3d
2 changed files with 43 additions and 3 deletions
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CloudProviderToken extends Model
|
||||
class CloudProviderToken extends BaseModel
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('cloud_provider_tokens', function (Blueprint $table) {
|
||||
$table->string('uuid')->nullable()->unique()->after('id');
|
||||
});
|
||||
|
||||
// Generate UUIDs for existing records
|
||||
$tokens = DB::table('cloud_provider_tokens')->whereNull('uuid')->get();
|
||||
foreach ($tokens as $token) {
|
||||
DB::table('cloud_provider_tokens')
|
||||
->where('id', $token->id)
|
||||
->update(['uuid' => (string) new Cuid2]);
|
||||
}
|
||||
|
||||
// Make uuid non-nullable after filling in values
|
||||
Schema::table('cloud_provider_tokens', function (Blueprint $table) {
|
||||
$table->string('uuid')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('cloud_provider_tokens', function (Blueprint $table) {
|
||||
$table->dropColumn('uuid');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue