Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: add UUID support to CloudProviderToken model

Andras Bacsai10003cec3dea
diff --git a/app/Models/CloudProviderToken.php b/app/Models/CloudProviderToken.php
index 607040269c..700ab0992d 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 0000000000..c1d19d3bc5
--- /dev/null
+++ b/database/migrations/2024_11_19_000001_add_uuid_to_cloud_provider_tokens.php
@@ -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');
+ });
+ }
+};