feat: establish reservation portal foundation
This commit is contained in:
53
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
53
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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->uuid('uuid')->unique();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->string('department')->nullable();
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamp('last_login_at')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
59
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
59
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedSmallInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->string('connection');
|
||||
$table->string('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
|
||||
$table->index(['connection', 'queue', 'failed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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('passkeys', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('credential_id')->unique();
|
||||
$table->json('credential');
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('passkeys');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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::table('users', function (Blueprint $table) {
|
||||
$table->text('two_factor_secret')->after('password')->nullable();
|
||||
$table->text('two_factor_recovery_codes')->after('two_factor_secret')->nullable();
|
||||
$table->timestamp('two_factor_confirmed_at')->after('two_factor_recovery_codes')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'two_factor_secret',
|
||||
'two_factor_recovery_codes',
|
||||
'two_factor_confirmed_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('permission_role', function (Blueprint $table) {
|
||||
$table->foreignId('permission_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
|
||||
$table->primary(['permission_id', 'role_id']);
|
||||
});
|
||||
|
||||
Schema::create('role_user', function (Blueprint $table) {
|
||||
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->primary(['role_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::create('external_identities', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('provider');
|
||||
$table->string('provider_subject');
|
||||
$table->string('tenant_id')->nullable();
|
||||
$table->string('provider_email');
|
||||
$table->json('claims')->nullable();
|
||||
$table->timestamp('last_login_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->unique(['provider', 'provider_subject']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('external_identities');
|
||||
Schema::dropIfExists('role_user');
|
||||
Schema::dropIfExists('permission_role');
|
||||
Schema::dropIfExists('permissions');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('snipe_assets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('snipe_asset_id')->unique();
|
||||
$table->string('asset_tag')->unique();
|
||||
$table->string('name');
|
||||
$table->string('serial')->nullable();
|
||||
$table->unsignedBigInteger('model_id')->nullable();
|
||||
$table->string('model_name')->nullable();
|
||||
$table->unsignedBigInteger('category_id')->nullable();
|
||||
$table->string('category_name')->nullable()->index();
|
||||
$table->string('manufacturer')->nullable();
|
||||
$table->unsignedBigInteger('status_id')->nullable();
|
||||
$table->string('status_name')->nullable();
|
||||
$table->unsignedBigInteger('location_id')->nullable();
|
||||
$table->string('location_name')->nullable()->index();
|
||||
$table->boolean('requestable')->default(false)->index();
|
||||
$table->string('assigned_type')->nullable();
|
||||
$table->unsignedBigInteger('assigned_id')->nullable();
|
||||
$table->string('image_url')->nullable();
|
||||
$table->timestampTz('source_updated_at')->nullable();
|
||||
$table->timestampTz('synced_at')->nullable();
|
||||
$table->string('content_hash', 64)->nullable();
|
||||
$table->boolean('active')->default(true)->index();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
|
||||
Schema::create('reservations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('reference')->unique();
|
||||
$table->foreignId('requester_id')->constrained('users')->restrictOnDelete();
|
||||
$table->text('purpose');
|
||||
$table->string('usage_location');
|
||||
$table->timestampTz('starts_at')->index();
|
||||
$table->timestampTz('ends_at')->index();
|
||||
$table->string('status')->index();
|
||||
$table->timestampTz('approval_deadline')->nullable()->index();
|
||||
$table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestampTz('approved_at')->nullable();
|
||||
$table->foreignId('rejected_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestampTz('rejected_at')->nullable();
|
||||
$table->text('decision_reason')->nullable();
|
||||
$table->foreignId('cancelled_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestampTz('cancelled_at')->nullable();
|
||||
$table->text('cancellation_reason')->nullable();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
|
||||
Schema::create('reservation_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('reservation_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('snipe_asset_id')->constrained('snipe_assets')->restrictOnDelete();
|
||||
$table->timestampTz('starts_at')->index();
|
||||
$table->timestampTz('ends_at')->index();
|
||||
$table->string('status')->index();
|
||||
$table->timestampTz('delivered_at')->nullable();
|
||||
$table->timestampTz('returned_at')->nullable();
|
||||
$table->string('checkout_reference')->nullable();
|
||||
$table->string('checkin_reference')->nullable();
|
||||
$table->text('condition_out')->nullable();
|
||||
$table->text('condition_in')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestampsTz();
|
||||
$table->unique(['reservation_id', 'snipe_asset_id']);
|
||||
});
|
||||
|
||||
Schema::create('approval_actions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('reservation_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('actor_id')->constrained('users')->restrictOnDelete();
|
||||
$table->string('action');
|
||||
$table->string('previous_status')->nullable();
|
||||
$table->string('new_status');
|
||||
$table->text('comment')->nullable();
|
||||
$table->timestampTz('created_at')->useCurrent();
|
||||
});
|
||||
|
||||
Schema::create('asset_blocks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('snipe_asset_id')->constrained('snipe_assets')->cascadeOnDelete();
|
||||
$table->timestampTz('starts_at')->index();
|
||||
$table->timestampTz('ends_at')->index();
|
||||
$table->text('reason');
|
||||
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
|
||||
$table->timestampsTz();
|
||||
});
|
||||
|
||||
if (DB::getDriverName() === 'pgsql') {
|
||||
DB::statement('CREATE EXTENSION IF NOT EXISTS btree_gist');
|
||||
DB::statement(<<<'SQL'
|
||||
ALTER TABLE reservation_items
|
||||
ADD CONSTRAINT reservation_items_no_blocking_overlap
|
||||
EXCLUDE USING gist (
|
||||
snipe_asset_id WITH =,
|
||||
tstzrange(starts_at, ends_at, '[)') WITH &&
|
||||
)
|
||||
WHERE (status IN ('held', 'reserved', 'ready', 'delivered'))
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('asset_blocks');
|
||||
Schema::dropIfExists('approval_actions');
|
||||
Schema::dropIfExists('reservation_items');
|
||||
Schema::dropIfExists('reservations');
|
||||
Schema::dropIfExists('snipe_assets');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('handover_records', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('reservation_item_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('type');
|
||||
$table->foreignId('operator_id')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignId('recipient_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->text('condition')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->json('snipe_response')->nullable();
|
||||
$table->timestampTz('created_at')->useCurrent();
|
||||
});
|
||||
|
||||
Schema::create('sync_runs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('type');
|
||||
$table->timestampTz('started_at');
|
||||
$table->timestampTz('finished_at')->nullable();
|
||||
$table->string('status')->index();
|
||||
$table->unsignedInteger('records_processed')->default(0);
|
||||
$table->unsignedInteger('records_created')->default(0);
|
||||
$table->unsignedInteger('records_updated')->default(0);
|
||||
$table->unsignedInteger('records_disabled')->default(0);
|
||||
$table->text('error_message')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('audit_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('actor_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('event')->index();
|
||||
$table->nullableMorphs('auditable');
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->json('before')->nullable();
|
||||
$table->json('after')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestampTz('created_at')->useCurrent()->index();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('audit_logs');
|
||||
Schema::dropIfExists('sync_runs');
|
||||
Schema::dropIfExists('handover_records');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user