CreateTranslatorTables::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 33
rs 9.6666
c 2
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Migration
5
 */
6
use Illuminate\Support\Facades\Schema;
7
use Illuminate\Database\Schema\Blueprint;
8
use Illuminate\Database\Migrations\Migration;
9
10
/**
11
 * Translator Migration
12
 *
13
 * @package  Hokan22\LaravelTranslator\migrations
14
 * @author   Alexander Viertel <[email protected]>
15
 * @license  http://opensource.org/licenses/MIT MIT
16
 */
17
class CreateTranslatorTables extends Migration
18
{
19
    /**
20
     * Run the migrations.
21
     *
22
     * @return void
23
     */
24
    public function up() {
25
        DB::beginTransaction();
26
27
        // Create table for storing roles
28
        Schema::create('translation_identifiers', function(Blueprint $table) {
29
            $table->increments('id')->unique();
30
            $table->text('identifier');
31
32
            $table->string('parameters', 512)->nullable();
33
            $table->string('group')->default('default');
34
35
            $table->string('page_name')->nullable();
36
            $table->text('description')->nullable();
37
38
            $table->timestamps();
39
        });
40
41
        // Create table for storing roles
42
        Schema::create('translations', function(Blueprint $table) {
43
            $table->integer('translation_identifier_id')->unsigned();
44
            $table->foreign('translation_identifier_id')->references('id')->on('translation_identifiers')->onDelete('cascade')->onUpdate('no action');
45
46
            $table->string('locale', 5);
47
            $table->primary(['translation_identifier_id', 'locale']);
48
49
            $table->text('translation');
50
51
            $table->timestamps();
52
        });
53
54
        DB::statement('ALTER TABLE `translations` CHANGE `updated_at` `updated_at` TIMESTAMP on update CURRENT_TIMESTAMP NULL DEFAULT NULL;');
55
56
        DB::commit();
57
    }
58
59
    /**
60
     * Reverse the migrations.
61
     *
62
     * @return void
63
     */
64
    public function down() {
65
        Schema::drop('translations');
66
        Schema::drop('translation_identifiers');
67
    }
68
}
69