first
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
53
database/factories/TranscriptionProjectFactory.php
Normal file
53
database/factories/TranscriptionProjectFactory.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\TranscriptionProject;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/** @extends Factory<TranscriptionProject> */
|
||||
class TranscriptionProjectFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'title' => fake()->sentence(4),
|
||||
'description' => fake()->optional()->sentence(),
|
||||
'owner_user_id' => User::factory(),
|
||||
'original_filename' => fake()->word() . '.mp3',
|
||||
'stored_audio_path' => 'transcriptions/' . Str::uuid() . '/audio/' . Str::random(20) . '.mp3',
|
||||
'mime_type' => 'audio/mpeg',
|
||||
'file_size' => fake()->numberBetween(100000, 50000000),
|
||||
'duration_seconds' => fake()->optional()->numberBetween(60, 3600),
|
||||
'language' => 'ms',
|
||||
'transcription_status' => 'pending',
|
||||
'transcription_engine' => 'faster-whisper',
|
||||
'transcript_text' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function completed(): static
|
||||
{
|
||||
return $this->state(fn () => [
|
||||
'transcription_status' => 'completed',
|
||||
'transcript_text' => fake()->paragraphs(3, true),
|
||||
'processed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function failed(): static
|
||||
{
|
||||
return $this->state(fn () => [
|
||||
'transcription_status' => 'failed',
|
||||
'error_message' => 'Connection refused',
|
||||
]);
|
||||
}
|
||||
|
||||
public function processing(): static
|
||||
{
|
||||
return $this->state(fn () => ['transcription_status' => 'processing']);
|
||||
}
|
||||
}
|
||||
43
database/factories/UserFactory.php
Normal file
43
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/** @extends Factory<User> */
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
protected static ?string $password;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'role' => 'user',
|
||||
'department_id' => null,
|
||||
'is_active' => true,
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
public function admin(): static
|
||||
{
|
||||
return $this->state(fn () => ['role' => 'admin']);
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn () => ['is_active' => false]);
|
||||
}
|
||||
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn () => ['email_verified_at' => null]);
|
||||
}
|
||||
}
|
||||
57
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
57
database/migrations/0001_01_01_000000_create_users_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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('departments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('code', 50)->nullable()->unique();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
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->enum('role', ['admin', 'user'])->default('user');
|
||||
$table->foreignId('department_id')->nullable()->constrained('departments')->nullOnDelete();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamp('last_login_at')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sessions');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('departments');
|
||||
}
|
||||
};
|
||||
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');
|
||||
}
|
||||
};
|
||||
59
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
59
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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->unsignedSmallInteger('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->string('connection');
|
||||
$table->string('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
|
||||
$table->index(['connection', 'queue', 'failed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
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('actor_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('actor_role', 50)->nullable();
|
||||
$table->string('action', 100)->index();
|
||||
$table->string('subject_type', 100)->nullable();
|
||||
$table->unsignedBigInteger('subject_id')->nullable();
|
||||
$table->foreignId('target_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->unsignedBigInteger('project_id')->nullable();
|
||||
$table->json('old_values')->nullable();
|
||||
$table->json('new_values')->nullable();
|
||||
$table->text('justification')->nullable();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->timestamp('created_at')->nullable()->index();
|
||||
|
||||
$table->index(['subject_type', 'subject_id']);
|
||||
$table->index('project_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('audit_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
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('transcription_projects', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->foreignId('owner_user_id')->constrained('users')->restrictOnDelete();
|
||||
$table->string('original_filename', 500);
|
||||
$table->string('stored_audio_path', 1000);
|
||||
$table->string('mime_type', 100);
|
||||
$table->unsignedBigInteger('file_size');
|
||||
$table->unsignedInteger('duration_seconds')->nullable();
|
||||
$table->string('language', 10)->default('ms');
|
||||
$table->enum('transcription_status', ['pending', 'processing', 'completed', 'failed'])->default('pending')->index();
|
||||
$table->string('transcription_engine', 50)->nullable();
|
||||
$table->longText('transcript_text')->nullable(); // encrypted via model cast
|
||||
$table->decimal('transcript_confidence', 5, 4)->nullable();
|
||||
$table->text('error_message')->nullable();
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('owner_user_id');
|
||||
});
|
||||
|
||||
Schema::create('project_collaborators', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('project_id')->constrained('transcription_projects')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->enum('role', ['editor', 'viewer'])->default('editor');
|
||||
$table->foreignId('added_by')->constrained('users')->restrictOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['project_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::create('transcript_versions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('project_id')->constrained('transcription_projects')->cascadeOnDelete();
|
||||
$table->foreignId('edited_by')->constrained('users')->restrictOnDelete();
|
||||
$table->unsignedInteger('version_number');
|
||||
$table->longText('old_text')->nullable();
|
||||
$table->longText('new_text');
|
||||
$table->string('change_summary', 500)->nullable();
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
$table->index(['project_id', 'version_number']);
|
||||
});
|
||||
|
||||
Schema::create('project_comments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('project_id')->constrained('transcription_projects')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
$table->text('message');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('project_comments');
|
||||
Schema::dropIfExists('transcript_versions');
|
||||
Schema::dropIfExists('project_collaborators');
|
||||
Schema::dropIfExists('transcription_projects');
|
||||
}
|
||||
};
|
||||
41
database/seeders/AdminUserSeeder.php
Normal file
41
database/seeders/AdminUserSeeder.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminUserSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$name = env('ADMIN_DEFAULT_NAME');
|
||||
$email = env('ADMIN_DEFAULT_EMAIL');
|
||||
$password = env('ADMIN_DEFAULT_PASSWORD');
|
||||
|
||||
if (! $name || ! $email || ! $password) {
|
||||
$this->command->warn(
|
||||
'Admin default tidak dicipta. Sila isi ADMIN_DEFAULT_NAME, ADMIN_DEFAULT_EMAIL, dan ADMIN_DEFAULT_PASSWORD dalam .env'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$admin = User::firstOrCreate(
|
||||
['email' => $email],
|
||||
[
|
||||
'name' => $name,
|
||||
'password' => Hash::make($password),
|
||||
'role' => 'admin',
|
||||
'is_active' => true,
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
);
|
||||
|
||||
if ($admin->wasRecentlyCreated) {
|
||||
$this->command->info("Admin '{$name}' ({$email}) berjaya dicipta.");
|
||||
} else {
|
||||
$this->command->info("Admin '{$email}' sudah wujud. Tiada perubahan.");
|
||||
}
|
||||
}
|
||||
}
|
||||
16
database/seeders/DatabaseSeeder.php
Normal file
16
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
DepartmentSeeder::class,
|
||||
AdminUserSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
29
database/seeders/DepartmentSeeder.php
Normal file
29
database/seeders/DepartmentSeeder.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Department;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DepartmentSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$departments = [
|
||||
['name' => 'Jabatan Pentadbiran', 'code' => 'JPA'],
|
||||
['name' => 'Jabatan Kewangan', 'code' => 'JKW'],
|
||||
['name' => 'Jabatan Kejuruteraan', 'code' => 'JKJ'],
|
||||
['name' => 'Jabatan Perancangan Bandar', 'code' => 'JPB'],
|
||||
['name' => 'Jabatan Kesihatan Persekitaran', 'code' => 'JKP'],
|
||||
['name' => 'Jabatan Pelesenan', 'code' => 'JPL'],
|
||||
['name' => 'Jabatan Undang-Undang', 'code' => 'JUU'],
|
||||
['name' => 'Jabatan Teknologi Maklumat', 'code' => 'JTM'],
|
||||
['name' => 'Jabatan Landskap & Rekreasi', 'code' => 'JLR'],
|
||||
['name' => 'Jabatan Penguatkuasaan', 'code' => 'JPK'],
|
||||
];
|
||||
|
||||
foreach ($departments as $dept) {
|
||||
Department::firstOrCreate(['code' => $dept['code']], $dept);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user