First commit
This commit is contained in:
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
44
database/migrations/2024_01_01_000001_create_roles_table.php
Normal file
44
database/migrations/2024_01_01_000001_create_roles_table.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000001_create_roles_table.php
|
||||
// Jadual roles untuk RBAC ringkas — admin, staff, viewer
|
||||
|
||||
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('roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique(); // admin, staff, viewer
|
||||
$table->string('label'); // Admin Sistem, Kakitangan, Pengguna
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('user_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
$table->unique(['user_id', 'role_id']);
|
||||
});
|
||||
|
||||
// Tambah kolum role pada users untuk single-role semudah mungkin
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('role')->default('viewer')->after('password');
|
||||
// role: admin | staff | viewer
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
Schema::dropIfExists('user_roles');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000002_create_categories_table.php
|
||||
// Kategori dokumen — boleh ditambah/diubah/dinyahaktifkan tanpa ubah code
|
||||
|
||||
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('categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name'); // Pelesenan, Cukai, dll.
|
||||
$table->string('slug')->unique(); // pelesenan, cukai, wifi-johor
|
||||
$table->text('description')->nullable();
|
||||
$table->string('color', 10)->default('#6c757d'); // warna badge UI
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->integer('sort_order')->default(0);
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000004_create_document_versions_table.php
|
||||
// Setiap upload PDF adalah satu versi baru — versi lama TIDAK dipadam
|
||||
// Ini adalah source of truth untuk fail asal
|
||||
|
||||
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('document_versions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('document_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedInteger('version_number'); // 1, 2, 3, ...
|
||||
$table->string('original_filename'); // nama fail asal
|
||||
$table->string('stored_path'); // path dalam storage
|
||||
$table->string('mime_type')->default('application/pdf');
|
||||
$table->unsignedBigInteger('file_size'); // dalam bytes
|
||||
$table->string('file_hash', 64)->nullable(); // SHA256 untuk detect duplicate
|
||||
$table->unsignedInteger('page_count')->nullable();
|
||||
$table->string('processing_status')->default('pending');
|
||||
// pending | processing | extracting | chunking | embedding | indexed | failed | extraction_failed
|
||||
$table->text('processing_error')->nullable(); // mesej error jika gagal
|
||||
$table->timestamp('processing_started_at')->nullable();
|
||||
$table->timestamp('processing_completed_at')->nullable();
|
||||
$table->boolean('is_current')->default(false); // hanya satu versi = current
|
||||
$table->text('change_notes')->nullable(); // nota perubahan versi
|
||||
$table->foreignId('uploaded_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['document_id', 'version_number']);
|
||||
$table->index(['document_id', 'is_current']);
|
||||
$table->index('processing_status');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('document_versions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000005_create_document_chunks_table.php
|
||||
// Teks yang telah dipecahkan untuk embedding — dikaitkan dengan versi dokumen
|
||||
// Teks asal disimpan di sini untuk audit, re-embed, dan preview
|
||||
|
||||
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('document_chunks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('document_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('document_version_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedInteger('chunk_index'); // 0, 1, 2, ...
|
||||
$table->unsignedInteger('page_number')->nullable(); // muka surat PDF
|
||||
$table->text('content'); // teks chunk asal
|
||||
$table->unsignedInteger('token_count')->nullable(); // anggaran token
|
||||
$table->string('section_heading')->nullable(); // heading jika ada
|
||||
$table->string('qdrant_point_id', 36)->nullable()->unique();
|
||||
// UUID simpan di Qdrant — untuk update/delete tepat
|
||||
$table->boolean('is_embedded')->default(false);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamp('embedded_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['document_version_id', 'chunk_index']);
|
||||
$table->index(['document_id', 'is_active']);
|
||||
$table->index('qdrant_point_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('document_chunks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000006_create_knowledge_items_table.php
|
||||
// Knowledge items manual — FAQ, Q&A rasmi, polisi ringkas, nota dalaman
|
||||
// Ini pelengkap kepada dokumen PDF — admin boleh tambah terus tanpa upload fail
|
||||
|
||||
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('knowledge_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('category_id')->constrained()->restrictOnDelete();
|
||||
$table->string('item_type');
|
||||
// faq | policy | note | announcement
|
||||
$table->string('title'); // soalan / tajuk polisi
|
||||
$table->text('content'); // jawapan / kandungan penuh
|
||||
$table->text('content_short')->nullable(); // ringkasan (optional)
|
||||
$table->json('tags')->nullable();
|
||||
$table->string('language', 10)->default('ms');
|
||||
$table->date('effective_date')->nullable();
|
||||
$table->date('expiry_date')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->boolean('is_public')->default(true); // boleh dicari oleh public
|
||||
$table->string('qdrant_point_id', 36)->nullable()->unique();
|
||||
$table->boolean('is_embedded')->default(false);
|
||||
$table->timestamp('embedded_at')->nullable();
|
||||
$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', 'item_type']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('knowledge_items');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000007_create_chat_sessions_table.php
|
||||
// Sesi perbualan chatbot — satu sesi boleh ada banyak soalan
|
||||
|
||||
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('chat_sessions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('session_token', 64)->unique(); // untuk public user tanpa login
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
|
||||
// null = soal semua kategori, ada nilai = tapis kategori
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
$table->timestamp('last_activity_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['user_id']);
|
||||
$table->index('last_activity_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chat_sessions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000008_create_chat_logs_table.php
|
||||
// Log setiap pertanyaan + jawapan AI + sumber yang digunakan
|
||||
// Ini penting untuk audit, improve FAQ, dan semak kualiti jawapan
|
||||
|
||||
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('chat_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('chat_session_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->text('question'); // soalan user
|
||||
$table->text('answer'); // jawapan AI
|
||||
$table->json('sources_used')->nullable();
|
||||
// array of: {type, title, category, page, chunk_id, score}
|
||||
$table->json('context_chunks')->nullable(); // chunk teks yang dihantar ke model
|
||||
$table->string('model_used')->nullable(); // nama model Ollama
|
||||
$table->integer('tokens_used')->nullable(); // anggaran token
|
||||
$table->float('response_time')->nullable(); // masa (saat)
|
||||
$table->boolean('has_answer')->default(true); // false = model tidak tahu
|
||||
$table->boolean('is_flagged')->default(false); // admin flag untuk semak
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['chat_session_id']);
|
||||
$table->index(['user_id', 'created_at']);
|
||||
$table->index('is_flagged');
|
||||
$table->index('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chat_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000009_create_chat_feedbacks_table.php
|
||||
// Feedback pengguna untuk setiap jawapan AI
|
||||
// Admin boleh convert soalan yang gagal dijawab kepada FAQ rasmi
|
||||
|
||||
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('chat_feedbacks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('chat_log_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('rating');
|
||||
// helpful | not_helpful | partially_helpful
|
||||
$table->text('comment')->nullable(); // komen pembetulan user
|
||||
$table->text('correct_answer')->nullable(); // jawapan betul (dari user)
|
||||
$table->boolean('converted_to_faq')->default(false);
|
||||
$table->foreignId('converted_faq_id')->nullable()->constrained('knowledge_items')->nullOnDelete();
|
||||
$table->foreignId('reviewed_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamp('reviewed_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['chat_log_id']);
|
||||
$table->index(['rating', 'converted_to_faq']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chat_feedbacks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000010_create_audit_logs_table.php
|
||||
// Audit trail sistem — rekod semua tindakan penting oleh admin/sistem
|
||||
// Tidak boleh diubah atau dipadam — append-only log
|
||||
|
||||
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('audit_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('event');
|
||||
// document.uploaded | document.activated | document.deactivated
|
||||
// document.reindexed | document.version_added
|
||||
// knowledge_item.created | knowledge_item.updated | knowledge_item.deactivated
|
||||
// category.created | category.updated
|
||||
// faq.converted_from_feedback
|
||||
// system.reindex_started | system.reindex_completed
|
||||
$table->string('auditable_type')->nullable(); // model class
|
||||
$table->unsignedBigInteger('auditable_id')->nullable();
|
||||
$table->json('old_values')->nullable(); // data sebelum perubahan
|
||||
$table->json('new_values')->nullable(); // data selepas perubahan
|
||||
$table->text('description')->nullable(); // huraian tindakan
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
$table->timestamp('created_at'); // hanya created_at (append-only)
|
||||
|
||||
$table->index(['user_id', 'created_at']);
|
||||
$table->index(['auditable_type', 'auditable_id']);
|
||||
$table->index(['event', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('audit_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// database/migrations/2024_01_01_000011_create_processing_logs_table.php
|
||||
// Log status pemprosesan setiap document_version — untuk debug dan monitoring
|
||||
// Berbeza dari audit_logs: ini untuk teknikal, bukan untuk governance
|
||||
|
||||
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('processing_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('processable_type'); // DocumentVersion | KnowledgeItem
|
||||
$table->unsignedBigInteger('processable_id');
|
||||
$table->string('stage');
|
||||
// upload | extract | chunk | embed | qdrant_sync | completed | failed
|
||||
$table->string('status'); // started | completed | failed
|
||||
$table->text('message')->nullable();
|
||||
$table->json('metadata')->nullable(); // data tambahan (chunk count, page count, dsb.)
|
||||
$table->float('duration')->nullable(); // masa dalam saat
|
||||
$table->timestamp('created_at');
|
||||
|
||||
$table->index(['processable_type', 'processable_id']);
|
||||
$table->index(['stage', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('processing_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
// database/migrations/2026_04_08_000001_add_chunk_review_fields_to_document_chunks.php
|
||||
// Tambah sokongan Chunk Review & Editing:
|
||||
// - Teks berlapis: cleaned_text, final_text (content kekal sebagai raw_text)
|
||||
// - Status enum: chunk_status
|
||||
// - Flags: is_edited, exclude_from_index, needs_reindex
|
||||
// - Split tracking: parent_chunk_id, split_group_id, split_order
|
||||
// - Admin metadata: edited_by, edited_at, last_embedded_at, notes
|
||||
|
||||
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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('document_chunks', function (Blueprint $table) {
|
||||
// === Teks berlapis ===
|
||||
// content sedia ada = raw_text (teks asal extraction — TIDAK PERNAH DIUBAH)
|
||||
$table->longText('cleaned_text')->nullable()->after('content');
|
||||
// Auto-cleaned text — null bermakna tiada cleanup dilakukan
|
||||
$table->longText('final_text')->nullable()->after('cleaned_text');
|
||||
// Teks akhir untuk embedding — null bermakna guna cleaned_text atau content
|
||||
|
||||
// === Status chunk ===
|
||||
// Values: pending, indexed, needs_review, needs_reindex, excluded, superseded, failed_embedding
|
||||
$table->string('chunk_status', 25)->default('pending')->after('final_text');
|
||||
|
||||
// === Admin flags ===
|
||||
$table->boolean('is_edited')->default(false)->after('is_active');
|
||||
// true jika admin pernah edit final_text
|
||||
$table->boolean('exclude_from_index')->default(false)->after('is_edited');
|
||||
// true jika admin kecualikan chunk dari indexing
|
||||
$table->boolean('needs_reindex')->default(false)->after('exclude_from_index');
|
||||
// true jika final_text berubah tapi belum direindex semula
|
||||
|
||||
// === Split tracking ===
|
||||
$table->unsignedBigInteger('parent_chunk_id')->nullable()->after('needs_reindex');
|
||||
// FK ke chunk asal jika ini adalah hasil split
|
||||
$table->foreign('parent_chunk_id')
|
||||
->references('id')
|
||||
->on('document_chunks')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->string('split_group_id', 36)->nullable()->after('parent_chunk_id');
|
||||
// UUID bersama untuk semua siblings dalam satu split operation
|
||||
|
||||
$table->unsignedTinyInteger('split_order')->nullable()->after('split_group_id');
|
||||
// 0, 1, 2... untuk susun atur dalam split group
|
||||
|
||||
// === Admin editing metadata ===
|
||||
$table->unsignedBigInteger('edited_by')->nullable()->after('split_order');
|
||||
$table->foreign('edited_by')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->timestamp('edited_at')->nullable()->after('edited_by');
|
||||
// Bila admin terakhir kali edit
|
||||
|
||||
$table->timestamp('last_embedded_at')->nullable()->after('edited_at');
|
||||
// Masa embed terkini (berbeza dari embedded_at = masa embed pertama)
|
||||
|
||||
$table->text('notes')->nullable()->after('last_embedded_at');
|
||||
// Nota admin untuk chunk ini
|
||||
|
||||
// === Indexes ===
|
||||
$table->index('chunk_status');
|
||||
$table->index(['document_version_id', 'chunk_status']);
|
||||
$table->index('needs_reindex');
|
||||
$table->index('split_group_id');
|
||||
});
|
||||
|
||||
// Kemaskini chunk_status sedia ada berdasarkan is_embedded dan is_active
|
||||
DB::statement("
|
||||
UPDATE document_chunks
|
||||
SET
|
||||
chunk_status = CASE
|
||||
WHEN is_active = 0 THEN 'excluded'
|
||||
WHEN is_embedded = 1 AND is_active = 1 THEN 'indexed'
|
||||
ELSE 'pending'
|
||||
END,
|
||||
last_embedded_at = embedded_at
|
||||
");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('document_chunks', function (Blueprint $table) {
|
||||
$table->dropForeign(['parent_chunk_id']);
|
||||
$table->dropForeign(['edited_by']);
|
||||
|
||||
$table->dropIndex(['chunk_status']);
|
||||
$table->dropIndex(['document_version_id', 'chunk_status']);
|
||||
$table->dropIndex(['needs_reindex']);
|
||||
$table->dropIndex(['split_group_id']);
|
||||
|
||||
$table->dropColumn([
|
||||
'cleaned_text',
|
||||
'final_text',
|
||||
'chunk_status',
|
||||
'is_edited',
|
||||
'exclude_from_index',
|
||||
'needs_reindex',
|
||||
'parent_chunk_id',
|
||||
'split_group_id',
|
||||
'split_order',
|
||||
'edited_by',
|
||||
'edited_at',
|
||||
'last_embedded_at',
|
||||
'notes',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
// database/migrations/2026_04_08_000002_create_chunk_audits_table.php
|
||||
// Audit trail khusus untuk operasi chunk:
|
||||
// edit_final_text, exclude, include, reindex, split_parent, split_child
|
||||
//
|
||||
// Berbeza dari audit_logs: chunk_audits simpan perubahan teks sebenar (old/new final_text)
|
||||
// yang terlalu besar untuk disimpan dalam kolum JSON audit_logs.
|
||||
|
||||
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('chunk_audits', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId('document_chunk_id')
|
||||
->constrained('document_chunks')
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->foreignId('user_id')
|
||||
->nullable()
|
||||
->constrained('users')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->string('operation', 30);
|
||||
// 'edit_final_text' | 'exclude' | 'include' | 'reindex'
|
||||
// | 'split_parent' | 'split_child'
|
||||
|
||||
// Perubahan teks (boleh null jika operasi bukan edit teks)
|
||||
$table->longText('old_final_text')->nullable();
|
||||
$table->longText('new_final_text')->nullable();
|
||||
|
||||
// Perubahan status
|
||||
$table->string('old_status', 25)->nullable();
|
||||
$table->string('new_status', 25)->nullable();
|
||||
|
||||
// Metadata tambahan (parent_chunk_id, split_group_id, bilangan segmen, dll.)
|
||||
$table->json('metadata')->nullable();
|
||||
|
||||
$table->text('notes')->nullable();
|
||||
// Nota admin yang dimasukkan semasa operasi
|
||||
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
|
||||
// Append-only — hanya created_at, tiada updated_at
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
$table->index(['document_chunk_id', 'created_at']);
|
||||
$table->index('operation');
|
||||
$table->index('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chunk_audits');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user