Add migration files for language and translation management: Created migrations for languages, translations, and user_languages tables to support the universal translation system. Each migration includes necessary fields, constraints, and indexes to ensure efficient data handling and relationships.

This commit is contained in:
Ümit Tunç
2025-10-01 04:15:03 -03:00
parent e9944f2460
commit 7cbbf521e1
3 changed files with 136 additions and 0 deletions
@@ -0,0 +1,41 @@
<?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('languages', function (Blueprint $table) {
$table->id();
$table->string('code', 10)->unique()->comment('Language code (tr, en, de)');
$table->string('name', 100)->comment('Language name in English');
$table->string('native_name', 100)->comment('Language name in native language');
$table->string('flag', 10)->nullable()->comment('Flag emoji or icon code');
$table->enum('direction', ['ltr', 'rtl'])->default('ltr')->comment('Text direction');
$table->boolean('is_active')->default(true)->comment('Is language active?');
$table->boolean('is_default')->default(false)->comment('Is default language?');
$table->integer('sort_order')->default(0)->comment('Display order');
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
$table->index(['is_active', 'sort_order']);
$table->index('code');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('languages');
}
};
@@ -0,0 +1,52 @@
<?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('translations', function (Blueprint $table) {
$table->id();
$table->string('translatable_type')->comment('Model class name');
$table->unsignedBigInteger('translatable_id')->comment('Model ID');
$table->string('language_code', 10)->comment('Language code');
$table->string('field_name', 100)->comment('Field name to translate');
$table->longText('field_value')->nullable()->comment('Translated value');
$table->enum('status', ['draft', 'review', 'approved', 'published'])->default('draft')->comment('Translation status');
$table->integer('version')->default(1)->comment('Translation version');
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('approved_at')->nullable();
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
// Indexes for performance
$table->index(['translatable_type', 'translatable_id']);
$table->index(['language_code', 'status']);
$table->index(['created_by', 'status']);
$table->index('approved_by');
// Unique constraint: one translation per model+field+language
$table->unique(['translatable_type', 'translatable_id', 'language_code', 'field_name'], 'unique_translation');
// Foreign key for language
$table->foreign('language_code')->references('code')->on('languages')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('translations');
}
};
@@ -0,0 +1,43 @@
<?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('user_languages', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->string('language_code', 10);
$table->boolean('can_create')->default(true)->comment('Can create content in this language');
$table->boolean('can_edit')->default(true)->comment('Can edit content in this language');
$table->boolean('can_approve')->default(false)->comment('Can approve translations in this language');
$table->boolean('can_publish')->default(false)->comment('Can publish content in this language');
$table->timestamps();
// Unique constraint: one entry per user+language
$table->unique(['user_id', 'language_code']);
// Foreign key for language
$table->foreign('language_code')->references('code')->on('languages')->onDelete('cascade');
// Indexes
$table->index(['user_id', 'language_code']);
$table->index('language_code');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_languages');
}
};