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.

feat(migration): encrypt local file volumes content and paths

peaklabs-devedddbc8536ef
diff --git a/database/migrations/2025_01_30_125223_encrypt_local_file_volumes_fields.php b/database/migrations/2025_01_30_125223_encrypt_local_file_volumes_fields.php
new file mode 100644
index 0000000000..f29cdaa238
--- /dev/null
+++ b/database/migrations/2025_01_30_125223_encrypt_local_file_volumes_fields.php
@@ -0,0 +1,63 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('local_file_volumes', function (Blueprint $table) {
+ $table->text('mount_path')->nullable()->change();
+ });
+
+ if (DB::table('local_file_volumes')->exists()) {
+ $volumes = DB::table('local_file_volumes')->get();
+ foreach ($volumes as $volume) {
+ try {
+ DB::table('local_file_volumes')->where('id', $volume->id)->update([
+ 'fs_path' => $volume->fs_path ? Crypt::encryptString($volume->fs_path) : null,
+ 'mount_path' => $volume->mount_path ? Crypt::encryptString($volume->mount_path) : null,
+ 'content' => $volume->content ? Crypt::encryptString($volume->content) : null,
+ ]);
+ } catch (\Exception $e) {
+ Log::error('Error encrypting local file volume fields: '.$e->getMessage());
+ }
+ }
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('local_file_volumes', function (Blueprint $table) {
+ $table->string('fs_path')->change();
+ $table->string('mount_path')->nullable()->change();
+ $table->longText('content')->nullable()->change();
+ });
+
+ if (DB::table('local_file_volumes')->exists()) {
+ $volumes = DB::table('local_file_volumes')->get();
+ foreach ($volumes as $volume) {
+ try {
+ DB::table('local_file_volumes')->where('id', $volume->id)->update([
+ 'fs_path' => $volume->fs_path ? Crypt::decryptString($volume->fs_path) : null,
+ 'mount_path' => $volume->mount_path ? Crypt::decryptString($volume->mount_path) : null,
+ 'content' => $volume->content ? Crypt::decryptString($volume->content) : null,
+ ]);
+ } catch (\Exception $e) {
+ Log::error('Error decrypting local file volume fields: '.$e->getMessage());
+ }
+ }
+ }
+ }
+};