Files
beatbook/database/migrations/2026_09_12_000001_create_beatbook_tables.php
2026-09-12 20:45:05 +01:00

140 lines
6.2 KiB
PHP

<?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('businesses', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->string('email')->nullable();
$table->string('phone')->nullable();
$table->string('website')->nullable();
$table->string('status')->default('active')->index();
$table->timestamp('verified_at')->nullable();
$table->timestamps();
});
Schema::create('business_user', function (Blueprint $table) {
$table->id();
$table->foreignUlid('business_id')->constrained('businesses')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('role')->default('member');
$table->timestamps();
$table->unique(['business_id', 'user_id']);
});
Schema::create('dj_profiles', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignUlid('business_id')->nullable()->constrained('businesses')->nullOnDelete();
$table->string('stage_name');
$table->string('slug')->unique();
$table->string('headline')->nullable();
$table->text('bio')->nullable();
$table->string('city')->index();
$table->unsignedSmallInteger('service_radius_miles')->default(30);
$table->decimal('price_from', 10, 2)->nullable();
$table->string('profile_photo')->nullable();
$table->string('cover_photo')->nullable();
$table->timestamp('verified_at')->nullable();
$table->boolean('is_featured')->default(false)->index();
$table->boolean('is_published')->default(false)->index();
$table->decimal('average_rating', 3, 2)->default(0);
$table->unsignedInteger('review_count')->default(0);
$table->timestamps();
});
Schema::create('genres', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->timestamps();
});
Schema::create('dj_profile_genre', function (Blueprint $table) {
$table->foreignUlid('dj_profile_id')->constrained('dj_profiles')->cascadeOnDelete();
$table->foreignId('genre_id')->constrained()->cascadeOnDelete();
$table->primary(['dj_profile_id', 'genre_id']);
});
Schema::create('enquiries', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignUlid('dj_profile_id')->constrained('dj_profiles')->cascadeOnDelete();
$table->string('event_type');
$table->date('event_date')->index();
$table->time('start_time')->nullable();
$table->time('end_time')->nullable();
$table->string('venue');
$table->string('postcode')->nullable();
$table->unsignedInteger('guest_count')->nullable();
$table->decimal('budget', 10, 2)->nullable();
$table->text('message');
$table->string('status')->default('new')->index();
$table->timestamps();
});
Schema::create('bookings', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignUlid('enquiry_id')->nullable()->constrained('enquiries')->nullOnDelete();
$table->foreignId('client_id')->constrained('users')->cascadeOnDelete();
$table->foreignUlid('dj_profile_id')->constrained('dj_profiles')->cascadeOnDelete();
$table->date('event_date')->index();
$table->decimal('total', 10, 2);
$table->decimal('deposit', 10, 2)->default(0);
$table->string('status')->default('pending')->index();
$table->timestamp('paid_at')->nullable();
$table->timestamps();
});
Schema::create('reviews', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignUlid('booking_id')->constrained('bookings')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignUlid('dj_profile_id')->constrained('dj_profiles')->cascadeOnDelete();
$table->unsignedTinyInteger('rating');
$table->string('title')->nullable();
$table->text('body');
$table->string('status')->default('pending')->index();
$table->text('dj_reply')->nullable();
$table->timestamps();
$table->unique(['booking_id', 'user_id']);
});
Schema::create('cookie_consents', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('anonymous_id')->nullable()->index();
$table->boolean('analytics')->default(false);
$table->boolean('marketing')->default(false);
$table->string('policy_version');
$table->timestamp('consented_at');
$table->timestamps();
});
Schema::create('audit_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('action')->index();
$table->nullableMorphs('subject');
$table->json('meta')->nullable();
$table->string('ip_hash', 64)->nullable();
$table->timestamps();
});
}
public function down(): void
{
foreach (['audit_logs', 'cookie_consents', 'reviews', 'bookings', 'enquiries', 'dj_profile_genre', 'genres', 'dj_profiles', 'business_user', 'businesses'] as $table) {
Schema::dropIfExists($table);
}
}
};