| 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('analytics_snapshots', function (Blueprint $table) { | |
| $table->id(); | |
| $table->date('date'); | |
| $table->integer('hour')->nullable(); // 0-23 for hourly data, null for daily aggregates | |
| $table->decimal('revenue', 10, 2)->default(0); | |
| $table->decimal('profit', 10, 2)->default(0); | |
| $table->integer('orders_count')->default(0); | |
| $table->integer('customers_count')->default(0); | |
| $table->decimal('avg_order_value', 8, 2)->default(0); | |
| $table->decimal('conversion_rate', 5, 4)->default(0); // 0.0000 to 1.0000 | |
| $table->timestamps(); | |
| // Indexes for performance | |
| $table->index(['date', 'hour']); | |
| $table->index('date'); | |
| }); | |
| } | |
| /** | |
| * Reverse the migrations. | |
| */ | |
| public function down(): void | |
| { | |
| Schema::dropIfExists('analytics_snapshots'); | |
| } | |
| }; | |