41 lines
1.6 KiB
PHP
41 lines
1.6 KiB
PHP
<?php
|
|
// database/migrations/2024_01_01_000003_create_documents_table.php
|
|
// Metadata dokumen utama — satu rekod per dokumen (bukan per versi)
|
|
// Setiap dokumen boleh ada banyak versi dalam document_versions
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
Schema::create('documents', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('category_id')->constrained()->restrictOnDelete();
|
|
$table->string('title');
|
|
$table->text('description')->nullable();
|
|
$table->string('status')->default('draft');
|
|
// status: draft | processing | active | inactive | failed
|
|
$table->boolean('is_active')->default(false);
|
|
$table->date('effective_date')->nullable(); // tarikh kuat kuasa
|
|
$table->date('expiry_date')->nullable(); // tarikh luput (optional)
|
|
$table->json('tags')->nullable(); // ["lesen", "perniagaan"]
|
|
$table->string('language', 10)->default('ms');
|
|
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
|
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
|
|
$table->index(['category_id', 'is_active']);
|
|
$table->index('status');
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('documents');
|
|
}
|
|
};
|