LP53-Services-BD-CMS/database/migrations/2023_02_17_160319_lignes_commandes.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2023-03-03 13:45:51 +01:00
<?php
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
{
2023-03-03 15:43:38 +01:00
Schema::create('lignes_commandes', function (Blueprint $table){
2023-03-03 13:45:51 +01:00
$table->engine = 'InnoDB';
$table->bigIncrements('id')->unsigned();
$table->bigInteger('commandes_id')->unsigned();
2023-03-03 15:43:38 +01:00
$table->bigInteger('produits_id')->unsigned();
2023-03-03 13:45:51 +01:00
$table->integer('quantite')->nullable();
2023-03-03 15:43:38 +01:00
$table->float("prix_vente")->nullable();
2023-03-03 13:45:51 +01:00
$table->timestamps();
2023-03-03 15:43:38 +01:00
$table->index("commandes_id");
$table->index("produits_id");
$table->index("quantite");
$table->index("prix_vente");
2023-03-03 13:45:51 +01:00
});
2023-03-03 15:43:38 +01:00
Schema::table('lignes_commandes', function (Blueprint $table){
2023-03-03 13:45:51 +01:00
$table->foreign('commandes_id')->references('id')->on('commandes')->onUpdate('cascade')->onDelete('cascade');
2023-03-03 15:43:38 +01:00
$table->foreign('produits_id')->references('id')->on('produits')->onUpdate('cascade')->onDelete('cascade');
2023-03-03 13:45:51 +01:00
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
2023-03-03 15:43:38 +01:00
Schema::dropIfExists('lignes_commandes');
2023-03-03 13:45:51 +01:00
}
};