CreateVersionsTable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 20 1
A down() 0 4 1
1
<?php
2
/**
3
 * No Namespace
4
 *
5
 * This file is part of the overtrue/laravel-versionable.
6
 * ------------------------------------------------------
7
 * (c) overtrue <[email protected]>
8
 * This source file is subject to the MIT license that is bundled.
9
 */
10
11
use Illuminate\Database\Migrations\Migration;
12
use Illuminate\Database\Schema\Blueprint;
13
use Illuminate\Support\Facades\Schema;
14
15
/**
16
 * Class CreateVersionsTable
17
 * @author 安正超 - overtrue
18
 * @github https://github.com/overtrue
19
 */
20
class CreateVersionsTable extends Migration
21
{
22
    /**
23
     * Run the migrations.
24
     */
25
    public function up(): void
26
    {
27
        Schema::create('versions', static function (Blueprint $table) {
28
            $table->{config('versionable.key_type', 'unsignedBigInteger')}('id')
29
                ->primary();
30
            $table->unsignedBigInteger('version_number');
31
            $table->{config('versionable.user_key_type', 'unsignedBigInteger')}(
32
                config('versionable.user_foreign_key', 'user_id')
33
            );
34
            $table->string('versionable_id');
35
            $table->string('versionable_type');
36
            $table->json('contents')->nullable();
37
            $table->timestamps();
38
39
            $table->unique(
40
                ['versionable_id', 'versionable_type', 'version_number'],
41
                'unique_version_for_model'
42
            );
43
        });
44
    }
45
46
    /**
47
     * Reverse the migrations.
48
     */
49
    public function down(): void
50
    {
51
        Schema::dropIfExists('versions');
52
    }
53
}
54