2026_05_06_151148_create_cars_table.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. /*
  6. * Миграция: создаёт таблицу cars — основная таблица каталога автомобилей.
  7. * Создана: 2026-05-06
  8. * Индексы: idx_make_model (поиск по марке/модели), idx_year, idx_status (фильтрация в списке)
  9. * photos_gallery — TEXT/JSON-массив путей к файлам (кастуется в array моделью Car)
  10. * options — TEXT/JSON-массив выбранных опций комплектации
  11. */
  12. return new class extends Migration
  13. {
  14. public function up(): void
  15. {
  16. Schema::create('cars', function (Blueprint $table) {
  17. $table->unsignedBigInteger('id')->autoIncrement();
  18. $table->enum('status', ['active', 'sold', 'draft'])->default('active');
  19. $table->enum('condition', ['new', 'used'])->default('used');
  20. $table->string('make', 64);
  21. $table->string('model', 64);
  22. $table->string('generation', 64)->nullable();
  23. $table->smallInteger('year')->unsigned();
  24. $table->string('vin', 17)->nullable();
  25. $table->string('plate', 20)->nullable();
  26. $table->string('body_type', 32)->nullable();
  27. $table->tinyInteger('doors')->unsigned()->nullable();
  28. $table->string('color_exterior', 32)->nullable();
  29. $table->string('color_interior', 32)->nullable();
  30. $table->enum('engine_type', ['petrol', 'diesel', 'hybrid', 'electric', 'gas', 'other'])->nullable();
  31. $table->decimal('engine_volume', 3, 1)->nullable();
  32. $table->smallInteger('engine_power_hp')->unsigned()->nullable();
  33. $table->enum('transmission', ['manual', 'automatic', 'robot', 'variator', 'electric'])->nullable();
  34. $table->enum('drive', ['FWD', 'RWD', 'AWD', '4WD'])->nullable();
  35. $table->unsignedInteger('mileage_km')->nullable();
  36. $table->enum('steering', ['left', 'right'])->default('left');
  37. $table->tinyInteger('owners_count')->unsigned()->nullable();
  38. $table->boolean('customs_cleared')->default(true);
  39. $table->enum('pts', ['original', 'duplicate', 'electronic'])->nullable();
  40. $table->boolean('accident_free')->default(false);
  41. $table->unsignedInteger('price_usd')->nullable();
  42. $table->unsignedBigInteger('price_rub')->nullable();
  43. $table->unsignedBigInteger('price_vladivostok')->nullable();
  44. $table->unsignedBigInteger('price_moscow')->nullable();
  45. $table->boolean('price_negotiable')->default(false);
  46. $table->string('country_origin', 64)->nullable();
  47. $table->string('city', 64)->nullable();
  48. $table->text('options')->nullable();
  49. $table->string('title', 128)->nullable();
  50. $table->text('description')->nullable();
  51. $table->string('photo_main', 512)->nullable();
  52. $table->text('photos_gallery')->nullable()->comment('JSON array of paths');
  53. $table->timestamps();
  54. $table->index(['make', 'model'], 'idx_make_model');
  55. $table->index('year', 'idx_year');
  56. $table->index('status', 'idx_status');
  57. });
  58. }
  59. /**
  60. * Reverse the migrations.
  61. */
  62. public function down(): void
  63. {
  64. Schema::dropIfExists('cars');
  65. }
  66. };