2025_05_31_180116_create_maf_views_table.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. $sql = "CREATE OR REPLACE VIEW mafs_view AS
  13. SELECT ps.*,
  14. ov.district_name,
  15. ov.area_name,
  16. ov.user_name,
  17. ov.object_address,
  18. mo.order_number,
  19. p.article,
  20. p.nomenclature_number,
  21. p.name_tz,
  22. p.type_tz,
  23. p.`type`,
  24. p.manufacturer_name,
  25. f.original_name as passport_name
  26. FROM products_sku ps
  27. LEFT JOIN orders_view ov ON ov.id = ps.order_id
  28. LEFT JOIN maf_orders mo ON ps.maf_order_id = mo.id
  29. LEFT JOIN products p ON p.id = ps.product_id
  30. LEFT JOIN files f ON f.id = ps.passport_id
  31. ";
  32. DB::unprepared($sql);
  33. }
  34. /**
  35. * Reverse the migrations.
  36. */
  37. public function down(): void
  38. {
  39. DB::unprepared("DROP VIEW IF EXISTS mafs_view");
  40. }
  41. };