move into sonardesk
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
<?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('commerce_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('parent_id')->nullable()->constrained('commerce_categories')->nullOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_products', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('category_id')->nullable()->constrained('commerce_categories')->nullOnDelete();
|
||||
$table->string('type')->default('physical');
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->string('sku')->nullable()->unique();
|
||||
$table->text('summary')->nullable();
|
||||
$table->longText('description')->nullable();
|
||||
$table->decimal('price', 12, 2)->default(0);
|
||||
$table->decimal('compare_at_price', 12, 2)->nullable();
|
||||
$table->decimal('cost_price', 12, 2)->nullable();
|
||||
$table->string('currency', 3)->default('GBP');
|
||||
$table->boolean('track_inventory')->default(true);
|
||||
$table->integer('stock_quantity')->default(0);
|
||||
$table->integer('low_stock_threshold')->default(5);
|
||||
$table->boolean('is_featured')->default(false);
|
||||
$table->string('status')->default('draft');
|
||||
$table->timestamp('published_at')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->index(['status', 'published_at']);
|
||||
});
|
||||
Schema::create('commerce_product_variants', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('product_id')->constrained('commerce_products')->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('sku')->unique();
|
||||
$table->decimal('price', 12, 2)->nullable();
|
||||
$table->integer('stock_quantity')->default(0);
|
||||
$table->json('options')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_customers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('email')->index();
|
||||
$table->string('first_name');
|
||||
$table->string('last_name');
|
||||
$table->string('company')->nullable();
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('tax_number')->nullable();
|
||||
$table->json('billing_address')->nullable();
|
||||
$table->json('shipping_address')->nullable();
|
||||
$table->string('status')->default('active');
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_orders', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('number')->unique();
|
||||
$table->foreignId('customer_id')->nullable()->constrained('commerce_customers')->nullOnDelete();
|
||||
$table->string('email');
|
||||
$table->string('status')->default('pending');
|
||||
$table->string('payment_status')->default('unpaid');
|
||||
$table->string('fulfilment_status')->default('unfulfilled');
|
||||
$table->string('currency', 3)->default('GBP');
|
||||
$table->decimal('subtotal', 12, 2)->default(0);
|
||||
$table->decimal('discount_total', 12, 2)->default(0);
|
||||
$table->decimal('shipping_total', 12, 2)->default(0);
|
||||
$table->decimal('tax_total', 12, 2)->default(0);
|
||||
$table->decimal('grand_total', 12, 2)->default(0);
|
||||
$table->json('billing_address')->nullable();
|
||||
$table->json('shipping_address')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamp('placed_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['status', 'payment_status']);
|
||||
});
|
||||
Schema::create('commerce_order_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('order_id')->constrained('commerce_orders')->cascadeOnDelete();
|
||||
$table->foreignId('product_id')->nullable()->constrained('commerce_products')->nullOnDelete();
|
||||
$table->foreignId('variant_id')->nullable()->constrained('commerce_product_variants')->nullOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('sku')->nullable();
|
||||
$table->unsignedInteger('quantity');
|
||||
$table->decimal('unit_price', 12, 2);
|
||||
$table->decimal('tax_total', 12, 2)->default(0);
|
||||
$table->decimal('line_total', 12, 2);
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_inventory_movements', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('product_id')->constrained('commerce_products')->cascadeOnDelete();
|
||||
$table->foreignId('variant_id')->nullable()->constrained('commerce_product_variants')->cascadeOnDelete();
|
||||
$table->integer('quantity');
|
||||
$table->string('reason');
|
||||
$table->string('reference_type')->nullable();
|
||||
$table->unsignedBigInteger('reference_id')->nullable();
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['reference_type', 'reference_id']);
|
||||
});
|
||||
Schema::create('commerce_promotions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('code')->nullable()->unique();
|
||||
$table->string('type')->default('percentage');
|
||||
$table->decimal('value', 12, 2);
|
||||
$table->decimal('minimum_order', 12, 2)->nullable();
|
||||
$table->unsignedInteger('usage_limit')->nullable();
|
||||
$table->unsignedInteger('times_used')->default(0);
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('ends_at')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->json('conditions')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_shipping_methods', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('code')->unique();
|
||||
$table->decimal('price', 12, 2)->default(0);
|
||||
$table->decimal('free_over', 12, 2)->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->json('settings')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_tax_rates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('country_code', 2)->nullable();
|
||||
$table->decimal('rate', 7, 4)->default(0);
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
Schema::create('commerce_payment_transactions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('order_id')->constrained('commerce_orders')->cascadeOnDelete();
|
||||
$table->string('provider');
|
||||
$table->string('provider_reference')->nullable()->index();
|
||||
$table->string('type')->default('payment');
|
||||
$table->string('status')->default('pending');
|
||||
$table->decimal('amount', 12, 2);
|
||||
$table->string('currency', 3);
|
||||
$table->json('payload')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
foreach (['commerce_payment_transactions', 'commerce_tax_rates', 'commerce_shipping_methods', 'commerce_promotions', 'commerce_inventory_movements', 'commerce_order_items', 'commerce_orders', 'commerce_customers', 'commerce_product_variants', 'commerce_products', 'commerce_categories'] as $table) {
|
||||
Schema::dropIfExists($table);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user