63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?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('documents', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('document_category_id')->constrained()->onDelete('cascade');
|
|
|
|
// Document metadata
|
|
$table->string('title');
|
|
$table->string('document_number')->unique()->nullable(); // e.g., BYL-2024-001
|
|
$table->text('description')->nullable();
|
|
$table->uuid('public_uuid')->unique(); // For public sharing links
|
|
|
|
// Access control
|
|
$table->enum('access_level', ['public', 'members', 'admin', 'board'])->default('members');
|
|
|
|
// Current version pointer (set after first version is created)
|
|
$table->foreignId('current_version_id')->nullable()->constrained('document_versions')->onDelete('set null');
|
|
|
|
// Status
|
|
$table->enum('status', ['active', 'archived'])->default('active');
|
|
$table->timestamp('archived_at')->nullable();
|
|
|
|
// User tracking
|
|
$table->foreignId('created_by_user_id')->constrained('users')->onDelete('cascade');
|
|
$table->foreignId('last_updated_by_user_id')->nullable()->constrained('users')->onDelete('set null');
|
|
|
|
// Statistics
|
|
$table->integer('view_count')->default(0);
|
|
$table->integer('download_count')->default(0);
|
|
$table->integer('version_count')->default(0);
|
|
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
|
|
// Indexes
|
|
$table->index('document_category_id');
|
|
$table->index('access_level');
|
|
$table->index('status');
|
|
$table->index('public_uuid');
|
|
$table->index('created_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('documents');
|
|
}
|
|
};
|