2017_12_30_000000_create_mediable_tables.php
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateMediableTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('media', function (Blueprint $table) {
$table->increments('id');
$table->string('disk', 32);
$table->string('directory', 68);
$table->string('filename', 121);
$table->string('extension', 28);
$table->string('mime_type', 128);
$table->string('aggregate_type', 32);
$table->integer('size')->unsigned();
$table->timestamps();
$table->softDeletes();
$table->index(['disk', 'directory']);
$table->unique(['disk', 'directory', 'filename', 'extension']);
$table->index('aggregate_type');
});
Schema::create('mediables', function (Blueprint $table) {
$table->integer('media_id')->unsigned();
$table->string('mediable_type', 152);
$table->integer('mediable_id')->unsigned();
$table->string('tag', 68);
$table->integer('order')->unsigned();
$table->primary(['media_id', 'mediable_type', 'mediable_id', 'tag']);
$table->index(['mediable_id', 'mediable_type']);
$table->index('tag');
$table->index('order');
$table->foreign('media_id')->references('id')->on('media')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('mediables');
Schema::drop('media');
}
}