<?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('coupons', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->enum('type', ['flat', 'percent', 'free_ship'])->default('flat');
$table->decimal('value', 10, 2); // Amount or percent value
$table->decimal('max_discount', 10, 2)->nullable(); // Cap for percent type
$table->decimal('min_order', 10, 2)->nullable(); // Minimum cart subtotal
$table->unsignedInteger('max_uses')->nullable(); // Global usage cap
$table->unsignedInteger('used_count')->default(0);
$table->foreignId('vendor_id')->nullable()->constrained('vendors')->nullOnDelete();
$table->json('conditions')->nullable(); // Reserved: product/category restrictions
$table->string('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamp('starts_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
$table->index(['code', 'is_active']);
});
}
public function down(): void
{
Schema::dropIfExists('coupons');
}
};