Replace dev/schema.sql with Laravel migrations in the backend

Baseline migration reproduces the production dump byte-for-byte (verified via
mariadb-dump diff); creates are hasTable-guarded so prod only records it.
Drop stock Laravel migrations that contradict prod and Sanctum's bundled one.
This commit is contained in:
kurogeek committed 2026-10-15 11:06:06 +00:00
1 parent d38f9a1a83
commit abf482eeb0
14 files changed
+164 -394

No files matched your search

@@ -1,32 +0,0 @@
<?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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
};
@@ -1,28 +0,0 @@
<?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('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('password_reset_tokens');
}
};
@@ -1,32 +0,0 @@
<?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('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('failed_jobs');
}
};
@@ -1,33 +0,0 @@
<?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('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_access_tokens');
}
};
@@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
// Name matches the only row in the production `migrations` table, so prod treats it as applied.
return new class extends Migration
{
public function up(): void
{
Schema::create('cache', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->text('value');
$table->unsignedInteger('expiration')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('cache');
}
};
@@ -0,0 +1,118 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Baseline for the tables that were created by hand in production (phpMyAdmin, MariaDB 10.6).
* Column order, types, collations and engines mirror the 2025-11-03 production dump exactly.
*
* Production already has these tables, so every create is guarded with Schema::hasTable();
* running `migrate` there only records this migration as applied.
*/
return new class extends Migration
{
public function up(): void
{
// category_id: 1 = Chiang Mai ("no-where-else"), 2 = Where Else. There is no `category` table.
$this->createUnlessExists('sub_category', function (Blueprint $table) {
$table->integer('id')->autoIncrement();
$table->integer('category_id')->nullable();
$table->dateTime('due_date')->nullable();
$table->text('name')->nullable();
$table->text('name_en')->nullable();
$table->binary('description_en')->nullable();
$table->binary('description')->nullable();
$table->integer('active')->nullable()->default(1)->comment('0 = inactive, 1 = active');
$table->dateTime('created_at');
$table->dateTime('updated_at');
$table->text('image_url')->nullable();
$table->text('image_name')->nullable();
}, longblob: ['description_en', 'description']);
// sub_category_ids: comma-separated sub_category.id list, queried with FIND_IN_SET.
// description / description_en: Editor.js JSON stored as longblob.
$this->createUnlessExists('article', function (Blueprint $table) {
$table->integer('id')->autoIncrement();
$table->integer('category_id')->nullable();
$table->text('sub_category_ids')->nullable();
$table->dateTime('due_date')->nullable();
$table->text('name')->nullable();
$table->text('name_en')->nullable();
$table->binary('description_en')->nullable();
$table->binary('description')->nullable();
$table->integer('active')->nullable()->default(1)->comment('0 = inactive, 1 = active');
$table->dateTime('created_at');
$table->dateTime('updated_at');
$table->text('image_url')->nullable();
$table->text('image_name')->nullable();
$table->integer('count_view')->nullable()->default(0);
}, longblob: ['description_en', 'description']);
$this->createUnlessExists('folder', function (Blueprint $table) {
$table->engine = 'MyISAM';
$table->collation = 'utf8mb3_unicode_ci';
$table->integer('id')->autoIncrement();
$table->string('name');
$table->integer('folder_type');
$table->dateTime('created_at');
});
foreach (['file_document', 'file_image', 'file_sound', 'file_video'] as $name) {
$this->createUnlessExists($name, function (Blueprint $table) {
$table->integer('id')->autoIncrement();
$table->text('name')->nullable();
$table->integer('user_id')->nullable();
$table->integer('folder_id')->nullable();
$table->dateTime('created_at')->nullable();
});
}
$this->createUnlessExists('users', function (Blueprint $table) {
$table->id();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('phone', 10)->nullable();
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->integer('role')->nullable()->comment('0 = Admin, 1 = Editor, 2 = Contributor');
$table->integer('active')->nullable()->default(1)->comment('0 = inactive, 1 = active');
$table->string('image_url')->nullable();
$table->string('image_name')->nullable();
$table->string('forgot_password_token')->nullable();
$table->dateTime('forgot_password_date')->nullable();
$table->timestamps();
$table->index('id', 'id');
});
}
public function down(): void
{
foreach (['users', 'file_video', 'file_sound', 'file_image', 'file_document', 'folder', 'article', 'sub_category'] as $name) {
Schema::dropIfExists($name);
}
}
/**
* @param string[] $longblob Blueprint has no longblob type (binary() is BLOB); widen these after create.
*/
private function createUnlessExists(string $name, Closure $define, array $longblob = []): void
{
if (Schema::hasTable($name)) {
return;
}
Schema::create($name, function (Blueprint $table) use ($define) {
$table->charset = 'utf8mb3';
$table->collation = 'utf8mb3_general_ci';
$define($table);
});
foreach ($longblob as $column) {
DB::statement("ALTER TABLE `$name` MODIFY `$column` LONGBLOB NULL DEFAULT NULL");
}
}
};