diff --git a/app/Models/CloudProviderToken.php b/app/Models/CloudProviderToken.php index 607040269..700ab0992 100644 --- a/app/Models/CloudProviderToken.php +++ b/app/Models/CloudProviderToken.php @@ -2,9 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; - -class CloudProviderToken extends Model +class CloudProviderToken extends BaseModel { protected $guarded = []; diff --git a/database/migrations/2024_11_19_000001_add_uuid_to_cloud_provider_tokens.php b/database/migrations/2024_11_19_000001_add_uuid_to_cloud_provider_tokens.php new file mode 100644 index 000000000..c1d19d3bc --- /dev/null +++ b/database/migrations/2024_11_19_000001_add_uuid_to_cloud_provider_tokens.php @@ -0,0 +1,42 @@ +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'); + }); + } +};