Skip to content

Commit 50b147c

Browse files
committed
DB: Planned out new entity table format via migrations
1 parent 08dfff0 commit 50b147c

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('entities', function (Blueprint $table) {
15+
$table->bigIncrements('id');
16+
$table->string('type', 10);
17+
$table->string('slug', 191);
18+
19+
$table->unsignedBigInteger('book_id')->nullable()->index();
20+
$table->unsignedInteger('priority')->nullable();
21+
22+
$table->timestamp('created_at')->nullable();
23+
$table->timestamp('updated_at')->nullable()->index();
24+
$table->timestamp('deleted_at')->nullable()->index();
25+
26+
$table->unsignedInteger('created_by')->nullable();
27+
$table->unsignedInteger('updated_by')->nullable();
28+
$table->unsignedInteger('owned_by')->nullable()->index();
29+
30+
$table->primary(['id', 'type'], 'entities_pk');
31+
});
32+
33+
Schema::create('entity_container_data', function (Blueprint $table) {
34+
$table->unsignedBigInteger('entity_id');
35+
$table->string('type', 10);
36+
$table->text('description');
37+
$table->text('description_html');
38+
39+
$table->unsignedBigInteger('default_template_id')->nullable();
40+
$table->unsignedInteger('image_id')->nullable();
41+
$table->unsignedInteger('sort_rule_id')->nullable();
42+
43+
$table->primary(['entity_id', 'type'], 'entity_container_data_pk');
44+
});
45+
46+
Schema::table('entity_page_data', function (Blueprint $table) {
47+
$table->unsignedBigInteger('page_id')->primary();
48+
$table->unsignedBigInteger('chapter_id')->index();
49+
50+
$table->boolean('draft')->index();
51+
$table->boolean('template')->index();
52+
$table->unsignedInteger('revision_count');
53+
$table->string('editor', 50);
54+
55+
$table->longText('html');
56+
$table->longText('text');
57+
$table->longText('markdown');
58+
});
59+
}
60+
61+
/**
62+
* Reverse the migrations.
63+
*/
64+
public function down(): void
65+
{
66+
Schema::dropIfExists('entities');
67+
Schema::dropIfExists('entity_container_data');
68+
Schema::dropIfExists('entity_page_data');
69+
}
70+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
// Migrate main data
15+
16+
// Fix up data (zeros to nulls, missing relations to nulls, etc)
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
//
25+
}
26+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
//
15+
}
16+
17+
/**
18+
* Reverse the migrations.
19+
*/
20+
public function down(): void
21+
{
22+
//
23+
}
24+
};
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::dropIfExists('pages');
15+
Schema::dropIfExists('chapters');
16+
Schema::dropIfExists('books');
17+
Schema::dropIfExists('bookshelves');
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*/
23+
public function down(): void
24+
{
25+
Schema::create('pages', function (Blueprint $table) {
26+
$table->unsignedInteger('id', true)->primary();
27+
$table->integer('book_id')->index();
28+
$table->integer('chapter_id')->index();
29+
$table->string('name');
30+
$table->string('slug')->index();
31+
$table->longText('html');
32+
$table->longText('text');
33+
$table->integer('priority')->index();
34+
35+
$table->timestamp('created_at')->nullable();
36+
$table->timestamp('updated_at')->nullable()->index();
37+
$table->integer('created_by')->index();
38+
$table->integer('updated_by')->index();
39+
40+
$table->boolean('draft')->default(0)->index();
41+
$table->longText('markdown');
42+
$table->integer('revision_count');
43+
$table->boolean('template')->default(0)->index();
44+
$table->timestamp('deleted_at')->nullable();
45+
46+
$table->unsignedInteger('owned_by')->index();
47+
$table->string('editor', 50)->default('');
48+
});
49+
50+
Schema::table('chapters', function (Blueprint $table) {
51+
$table->unsignedInteger('id', true)->primary();
52+
$table->integer('book_id')->index();
53+
$table->string('slug')->index();
54+
$table->text('name');
55+
$table->text('description');
56+
$table->integer('priority')->index();
57+
58+
$table->timestamp('created_at')->nullable();
59+
$table->timestamp('updated_at')->nullable();
60+
$table->integer('created_by')->index();
61+
$table->integer('updated_by')->index();
62+
63+
$table->timestamp('deleted_at')->nullable();
64+
$table->unsignedInteger('owned_by')->index();
65+
$table->text('description_html');
66+
$table->integer('default_template_id')->nullable();
67+
});
68+
69+
Schema::create('books', function (Blueprint $table) {
70+
$table->unsignedInteger('id', true)->primary();
71+
$table->string('name');
72+
$table->string('slug')->index();
73+
$table->text('description');
74+
$table->timestamp('created_at')->nullable();
75+
$table->timestamp('updated_at')->nullable();
76+
77+
$table->integer('created_by')->index();
78+
$table->integer('updated_by')->index();
79+
80+
$table->integer('image_id')->nullable();
81+
$table->timestamp('deleted_at')->nullable();
82+
$table->unsignedInteger('owned_by')->index();
83+
84+
$table->integer('default_template_id')->nullable();
85+
$table->text('description_html');
86+
$table->unsignedInteger('sort_rule_id')->nullable();
87+
});
88+
89+
Schema::create('bookshelves', function (Blueprint $table) {
90+
$table->unsignedInteger('id', true)->primary();
91+
$table->string('name', 180);
92+
$table->string('slug', 180)->index();
93+
$table->text('description');
94+
95+
$table->integer('created_by')->index();
96+
$table->integer('updated_by')->index();
97+
$table->integer('image_id')->nullable();
98+
99+
$table->timestamp('created_at')->nullable();
100+
$table->timestamp('updated_at')->nullable();
101+
$table->timestamp('deleted_at')->nullable();
102+
103+
$table->unsignedInteger('owned_by')->index();
104+
$table->text('description_html');
105+
});
106+
}
107+
};

0 commit comments

Comments
 (0)