setup complete

This commit is contained in:
2024-09-06 23:30:12 +03:00
parent a73ee21568
commit 6fc0a65b6f
22 changed files with 351 additions and 330 deletions
+105
View File
@@ -0,0 +1,105 @@
<?php
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class SetupDatabase extends Command
{
protected $signature = 'lucent:setup-db';
protected $description = 'Run to setup a new database';
public function handle()
{
$this->tableUsers();
$this->tableRecords();
$this->tableRevisions();
$this->tableSessions();
$this->tableCommandLogs();
$this->info("Lucent Database Setup Completed");
}
private function tableUsers(): void
{
Schema::create('users', function (Blueprint $table) {
$table->uuid("id")->primary();
$table->string('name')->nullable();
$table->string('email')->unique();
$table->jsonb('roles');
$table->string('createdAt');
$table->string('updatedAt');
$table->string('loggedInAt');
$table->string('mailToken')->nullable();
});
}
private function tableSessions(): void
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
private function tableRecords(): void
{
Schema::create('records', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('schema');
$table->string('status');
$table->jsonb('data');
$table->jsonb('_sys');
$table->jsonb('_file');
$table->text('search')->default("");
$table->index(['schema', '_sys->updatedAt', 'status']);
$table->index('search');
});
Schema::create('edges', function (Blueprint $table) {
$table->uuid('source');
$table->uuid('target');
$table->string('sourceSchema');
$table->string('targetSchema');
$table->string('field');
$table->string('rank');
$table->unique(['source', 'target', "field"]);
});
}
private function tableRevisions(): void
{
Schema::create('revisions', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('recordId');
$table->string('schema');
$table->jsonb('data');
$table->jsonb('_sys');
$table->jsonb('_file');
$table->jsonb('_edges');
});
}
private function tableCommandLogs(): void
{
Schema::create('command_logs', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('signature');
$table->integer('pid')->nullable();
$table->text('logs');
});
}
}