使用 Memory 数据库

This commit is contained in:
iVampireSP.com 2022-11-22 19:04:23 +08:00
parent e84a804598
commit 553424ec70
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 44 additions and 1 deletions

View File

@ -60,7 +60,7 @@
*/
class Task extends Model
{
use HasFactory, Cachable;
use HasFactory;
public $incrementing = false;
protected $fillable = [

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Drop foreign key
Schema::table('tasks', function (Blueprint $table) {
$table->dropForeign('tasks_host_id_foreign');
$table->dropForeign('tasks_user_id_foreign');
$table->dropForeign('tasks_module_id_foreign');
});
// run RAW SQL
DB::statement('ALTER TABLE tasks ENGINE=MEMORY;');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
DB::statement('ALTER TABLE tasks ENGINE=InnoDB;');
Schema::table('tasks', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('host_id')->references('id')->on('hosts')->onDelete('cascade');
$table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade');
});
}
};