davide-casiraghi/laravel-smart-blog

View on GitHub
database/migrations/create_post_translations_table.php.stub

Summary

Maintainability
Test Coverage
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostTranslationsTable extends Migration
{
    public function up()
    {
        Schema::create('post_translations', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('post_id')->unsigned();

            $table->string('title');
            $table->text('intro_text')->nullable();
            $table->text('body')->nullable();
            
            $table->string('slug')->nullable();
            $table->text('before_content')->nullable();
            $table->text('after_content')->nullable();

            $table->string('locale')->index();

            $table->unique(['post_id', 'locale']);
            $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('post_translations');
    }
}