DB: Planned out new entity table format via migrations

This commit is contained in:
Dan Brown 2025-09-15 15:14:53 +01:00
parent 08dfff05f4
commit 50b147c632
No known key found for this signature in database
GPG Key ID: 116094FE15AE65C0
4 changed files with 227 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('entities', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('type', 10);
$table->string('slug', 191);
$table->unsignedBigInteger('book_id')->nullable()->index();
$table->unsignedInteger('priority')->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable()->index();
$table->timestamp('deleted_at')->nullable()->index();
$table->unsignedInteger('created_by')->nullable();
$table->unsignedInteger('updated_by')->nullable();
$table->unsignedInteger('owned_by')->nullable()->index();
$table->primary(['id', 'type'], 'entities_pk');
});
Schema::create('entity_container_data', function (Blueprint $table) {
$table->unsignedBigInteger('entity_id');
$table->string('type', 10);
$table->text('description');
$table->text('description_html');
$table->unsignedBigInteger('default_template_id')->nullable();
$table->unsignedInteger('image_id')->nullable();
$table->unsignedInteger('sort_rule_id')->nullable();
$table->primary(['entity_id', 'type'], 'entity_container_data_pk');
});
Schema::table('entity_page_data', function (Blueprint $table) {
$table->unsignedBigInteger('page_id')->primary();
$table->unsignedBigInteger('chapter_id')->index();
$table->boolean('draft')->index();
$table->boolean('template')->index();
$table->unsignedInteger('revision_count');
$table->string('editor', 50);
$table->longText('html');
$table->longText('text');
$table->longText('markdown');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('entities');
Schema::dropIfExists('entity_container_data');
Schema::dropIfExists('entity_page_data');
}
};

View File

@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Migrate main data
// Fix up data (zeros to nulls, missing relations to nulls, etc)
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};

View File

@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
//
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};

View File

@ -0,0 +1,107 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::dropIfExists('pages');
Schema::dropIfExists('chapters');
Schema::dropIfExists('books');
Schema::dropIfExists('bookshelves');
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::create('pages', function (Blueprint $table) {
$table->unsignedInteger('id', true)->primary();
$table->integer('book_id')->index();
$table->integer('chapter_id')->index();
$table->string('name');
$table->string('slug')->index();
$table->longText('html');
$table->longText('text');
$table->integer('priority')->index();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable()->index();
$table->integer('created_by')->index();
$table->integer('updated_by')->index();
$table->boolean('draft')->default(0)->index();
$table->longText('markdown');
$table->integer('revision_count');
$table->boolean('template')->default(0)->index();
$table->timestamp('deleted_at')->nullable();
$table->unsignedInteger('owned_by')->index();
$table->string('editor', 50)->default('');
});
Schema::table('chapters', function (Blueprint $table) {
$table->unsignedInteger('id', true)->primary();
$table->integer('book_id')->index();
$table->string('slug')->index();
$table->text('name');
$table->text('description');
$table->integer('priority')->index();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->integer('created_by')->index();
$table->integer('updated_by')->index();
$table->timestamp('deleted_at')->nullable();
$table->unsignedInteger('owned_by')->index();
$table->text('description_html');
$table->integer('default_template_id')->nullable();
});
Schema::create('books', function (Blueprint $table) {
$table->unsignedInteger('id', true)->primary();
$table->string('name');
$table->string('slug')->index();
$table->text('description');
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->integer('created_by')->index();
$table->integer('updated_by')->index();
$table->integer('image_id')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->unsignedInteger('owned_by')->index();
$table->integer('default_template_id')->nullable();
$table->text('description_html');
$table->unsignedInteger('sort_rule_id')->nullable();
});
Schema::create('bookshelves', function (Blueprint $table) {
$table->unsignedInteger('id', true)->primary();
$table->string('name', 180);
$table->string('slug', 180)->index();
$table->text('description');
$table->integer('created_by')->index();
$table->integer('updated_by')->index();
$table->integer('image_id')->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->unsignedInteger('owned_by')->index();
$table->text('description_html');
});
}
};