Skip to content

A self-hosted media server and file management system

feat: remake images table

aminnausin4d3bc4d6b381
diff --git a/database/migrations/2026_05_28_210733_drop_old_images_table.php b/database/migrations/2026_05_28_210733_drop_old_images_table.php
new file mode 100644
index 00000000..25d7992c
--- /dev/null
+++ b/database/migrations/2026_05_28_210733_drop_old_images_table.php
@@ -0,0 +1,44 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+ /**
+ * Run the migrations.
+ */
+ public function up(): void {
+ Schema::dropIfExists('images');
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void {
+ Schema::create('images', function (Blueprint $table) {
+ $table->id();
+ $table->foreignUuid('metadata_uuid')->constrained('metadata', 'uuid')->cascadeOnDelete();
+
+ $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
+
+ $table->smallInteger('image_type');
+ $table->smallInteger('image_source');
+ $table->boolean('is_primary')->default(false);
+
+ $table->integer('width')->nullable();
+ $table->integer('height')->nullable();
+ $table->string('blurhash', 64)->nullable();
+
+ $table->text('path')->nullable();
+ $table->text('source_url')->nullable();
+
+ $table->timestampsTz();
+
+ $table->index(['metadata_uuid', 'image_type']);
+ });
+
+ DB::statement('CREATE UNIQUE INDEX images_primary_unique ON images (metadata_uuid, image_type) WHERE is_primary = true');
+ }
+};
diff --git a/database/migrations/2026_05_28_210734_remake_image_table.php b/database/migrations/2026_05_28_210734_remake_image_table.php
new file mode 100644
index 00000000..fe49a472
--- /dev/null
+++ b/database/migrations/2026_05_28_210734_remake_image_table.php
@@ -0,0 +1,55 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+ /**
+ * Run the migrations.
+ */
+ public function up(): void {
+ Schema::create('images', function (Blueprint $table) {
+ $table->id();
+ $table->uuidMorphs('imageable');
+
+ $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
+
+ $table->smallInteger('image_type');
+ $table->smallInteger('image_source');
+ $table->string('image_variant', 32)->nullable();
+
+ $table->integer('width')->nullable();
+ $table->integer('height')->nullable();
+ $table->unsignedBigInteger('size')->default(0);
+ $table->string('blur_hash', 64)->nullable();
+
+ $table->string('format', 10)->nullable();
+
+ $table->text('path')->nullable();
+ $table->text('source_url')->nullable();
+
+ $table->timestampTz('replaced_at')->nullable();
+
+ $table->timestampsTz();
+
+ $table->index(['imageable_type', 'imageable_id', 'image_type', 'replaced_at']);
+ });
+
+ Schema::table('metadata', function (Blueprint $table) {
+ $table->foreignId('primary_poster_id')->nullable()->constrained('images')->nullOnDelete();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void {
+ Schema::table('metadata', function (Blueprint $table) {
+ $table->dropForeign(['primary_poster_id']);
+ $table->dropColumn('primary_poster_id');
+ });
+
+ Schema::dropIfExists('images');
+ }
+};