id(); $table->foreignId('parent_id') ->nullable() ->constrained('documentation_folders') ->cascadeOnDelete(); $table->string('name'); $table->boolean('inherits_permissions')->default(true); $table->foreignId('created_by')->constrained('users')->restrictOnDelete(); $table->timestamps(); $table->index(['parent_id', 'name']); }); Schema::create('documentation_folder_permissions', function (Blueprint $table): void { $table->id(); $table->foreignId('folder_id')->constrained('documentation_folders')->cascadeOnDelete(); $table->string('subject_type', 16); $table->foreignId('role_id')->nullable()->constrained('roles')->cascadeOnDelete(); $table->foreignId('user_id')->nullable()->constrained('users')->cascadeOnDelete(); $table->boolean('can_read')->default(false); $table->boolean('can_write')->default(false); $table->timestamps(); $table->index(['folder_id', 'subject_type']); $table->index(['role_id', 'can_read', 'can_write'], 'documentation_folder_role_access_index'); $table->index(['user_id', 'can_read', 'can_write'], 'documentation_folder_user_access_index'); }); Schema::create('documentation_documents', function (Blueprint $table): void { $table->id(); $table->foreignId('folder_id')->constrained('documentation_folders')->cascadeOnDelete(); $table->string('name'); $table->unsignedInteger('last_version_number')->default(0); $table->foreignId('created_by')->constrained('users')->restrictOnDelete(); $table->timestamps(); $table->index(['folder_id', 'name']); }); Schema::create('documentation_document_versions', function (Blueprint $table): void { $table->id(); $table->foreignId('document_id')->constrained('documentation_documents')->cascadeOnDelete(); $table->foreignId('file_id')->constrained('files')->restrictOnDelete(); $table->unsignedInteger('version'); $table->unsignedBigInteger('file_size')->default(0); $table->foreignId('created_by')->constrained('users')->restrictOnDelete(); $table->timestamps(); $table->unique(['document_id', 'version']); }); } public function down(): void { Schema::dropIfExists('documentation_document_versions'); Schema::dropIfExists('documentation_documents'); Schema::dropIfExists('documentation_folder_permissions'); Schema::dropIfExists('documentation_folders'); } };