|
| 1 | +<?php |
| 2 | + |
| 3 | +use Illuminate\Database\Migrations\Migration; |
| 4 | +use Illuminate\Database\Schema\Blueprint; |
| 5 | +use Illuminate\Support\Facades\Schema; |
| 6 | + |
| 7 | +return new class extends Migration { |
| 8 | + /** |
| 9 | + * Run the migrations. |
| 10 | + */ |
| 11 | + public function up(): void |
| 12 | + { |
| 13 | + Schema::create('templates', function (Blueprint $table) { |
| 14 | + $table->bigIncrements('id'); |
| 15 | + $table->string('uuid', 191)->unique()->nullable(); |
| 16 | + $table->string('public_id', 191)->unique()->nullable(); |
| 17 | + $table->string('company_uuid', 191)->nullable()->index(); |
| 18 | + $table->string('created_by_uuid', 191)->nullable()->index(); |
| 19 | + $table->string('updated_by_uuid', 191)->nullable()->index(); |
| 20 | + |
| 21 | + // Identity |
| 22 | + $table->string('name'); |
| 23 | + $table->text('description')->nullable(); |
| 24 | + |
| 25 | + // Context type — defines which Fleetbase model this template is designed for. |
| 26 | + // e.g. 'order', 'invoice', 'transaction', 'shipping_label', 'receipt', 'report' |
| 27 | + $table->string('context_type')->default('generic')->index(); |
| 28 | + |
| 29 | + // Canvas dimensions (in mm by default, configurable via unit) |
| 30 | + $table->string('unit')->default('mm'); // mm, px, in |
| 31 | + $table->decimal('width', 10, 4)->default(210); // A4 width |
| 32 | + $table->decimal('height', 10, 4)->default(297); // A4 height |
| 33 | + $table->string('orientation')->default('portrait'); // portrait | landscape |
| 34 | + |
| 35 | + // Page settings |
| 36 | + $table->json('margins')->nullable(); // { top, right, bottom, left } |
| 37 | + $table->string('background_color')->nullable(); |
| 38 | + $table->string('background_image_uuid')->nullable(); |
| 39 | + |
| 40 | + // The full template content — array of element objects |
| 41 | + $table->longText('content')->nullable(); // JSON array of TemplateElement objects |
| 42 | + |
| 43 | + // Element type definitions / schema overrides (optional per-template customisation) |
| 44 | + $table->json('element_schemas')->nullable(); |
| 45 | + |
| 46 | + // Status |
| 47 | + $table->boolean('is_default')->default(false); |
| 48 | + $table->boolean('is_system')->default(false); |
| 49 | + $table->boolean('is_public')->default(false); |
| 50 | + |
| 51 | + $table->timestamps(); |
| 52 | + $table->softDeletes(); |
| 53 | + |
| 54 | + // Foreign keys |
| 55 | + $table->foreign('company_uuid')->references('uuid')->on('companies')->onDelete('cascade'); |
| 56 | + $table->foreign('created_by_uuid')->references('uuid')->on('users')->onDelete('set null'); |
| 57 | + $table->foreign('updated_by_uuid')->references('uuid')->on('users')->onDelete('set null'); |
| 58 | + |
| 59 | + // Composite indexes |
| 60 | + $table->index(['company_uuid', 'context_type']); |
| 61 | + $table->index(['company_uuid', 'is_default']); |
| 62 | + }); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Reverse the migrations. |
| 67 | + */ |
| 68 | + public function down(): void |
| 69 | + { |
| 70 | + Schema::dropIfExists('templates'); |
| 71 | + } |
| 72 | +}; |
0 commit comments