db seeder

This commit is contained in:
OMGiTzPomPom 2023-03-03 15:43:38 +01:00
parent 3d13369e05
commit 798996b615
7 changed files with 124 additions and 39 deletions

View File

@ -16,23 +16,20 @@ return new class extends Migration
$table->bigIncrements('id')->unsigned(); $table->bigIncrements('id')->unsigned();
$table->string('nom')->nullable(); $table->string('nom')->nullable();
$table->string('taille')->nullable(); $table->string("taille")->nullable();
$table->text('description')->nullable(); $table->text("description")->nullable();
$table->string('couleur')->nullable(); $table->string("couleur")->nullable();
$table->float('prix')->nullable(); $table->float("prix")->nullable();
$table->boolean('en_stock')->nullable(); $table->boolean("en_stock")->nullable();
$table->timestamps(); $table->timestamps();
$table->index("nom"); $table->index("nom");
$table->index("taille"); $table->index("taille");
$table->index("couleur"); $table->index("couleur");
$table->index("prix"); $table->index("prix");
$table->index("en_stock"); $table->index("en_stock");
}); });
} }
/** /**
@ -40,6 +37,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfexists('produits'); Schema::dropIfExists('produits');
} }
}; };

View File

@ -28,6 +28,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfexists('categories'); Schema::dropIfExists('categories');
} }
}; };

View File

@ -17,12 +17,11 @@ return new class extends Migration
$table->bigIncrements('id')->unsigned(); $table->bigIncrements('id')->unsigned();
$table->string('nom')->nullable(); $table->string('nom')->nullable();
$table->string('prenom')->nullable(); $table->string("prenom")->nullable();
$table->json('adresse')->default(new Expression('(JSON_OBJECT())')); $table->json("adresse")->default(new Expression('(JSON_OBJECT())'));
$table->timestamps(); $table->timestamps();
$table->index("nom"); $table->index("nom");
$table->index("prenom"); $table->index("prenom");
}); });
@ -33,6 +32,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfexists('clients'); Schema::dropIfExists('clients');
} }
}; };

View File

@ -14,14 +14,17 @@ return new class extends Migration
Schema::create('produits_categories', function (Blueprint $table){ Schema::create('produits_categories', function (Blueprint $table){
$table->engine = 'InnoDB'; $table->engine = 'InnoDB';
$table->bigInteger('products_id')->unsigned(); $table->bigInteger('produits_id')->unsigned();
$table->bigInteger('categories_id')->unsigned(); $table->bigInteger('categories_id')->unsigned();
$table->primary(['products_id', 'categories_id']); $table->primary(['produits_id', 'categories_id']);
$table->index("produits_id");
$table->index("categories_id");
}); });
Schema::table('produits_categories', function (Blueprint $table){ Schema::table('produits_categories', function (Blueprint $table){
$table->foreign('products_id')->references('id')->on('produits')->onUpdate('cascade')->onDelete('cascade'); $table->foreign('produits_id')->references('id')->on('produits')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('categories_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade'); $table->foreign('categories_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
}); });
} }
@ -31,6 +34,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfexists('produits_categories'); Schema::dropIfExists('produits_categories');
} }
}; };

View File

@ -16,10 +16,18 @@ return new class extends Migration
$table->engine = 'InnoDB'; $table->engine = 'InnoDB';
$table->bigIncrements('id')->unsigned(); $table->bigIncrements('id')->unsigned();
$table->date('date')->nullable(); $table->date('date');
$table->json('adresse')->default(new Expression('(JSON_OBJECT())')); $table->bigInteger('clients_id')->unsigned();
$table->json("adresse")->default(new Expression('(JSON_OBJECT())'));
$table->timestamps(); $table->timestamps();
$table->index("date");
$table->index("clients_id");
});
Schema::table('commandes', function (Blueprint $table){
$table->foreign('clients_id')->references('id')->on('clients')->onUpdate('cascade')->onDelete('cascade');
}); });
} }
@ -28,6 +36,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfexists('commandes'); Schema::dropIfExists('commandes');
} }
}; };

View File

@ -16,16 +16,21 @@ return new class extends Migration
$table->bigIncrements('id')->unsigned(); $table->bigIncrements('id')->unsigned();
$table->bigInteger('commandes_id')->unsigned(); $table->bigInteger('commandes_id')->unsigned();
$table->bigInteger('produits_id')->unsigned()->nullable(); $table->bigInteger('produits_id')->unsigned();
$table->integer('quantite')->nullable(); $table->integer('quantite')->nullable();
$table->float('prix_vente')->nullable(); $table->float("prix_vente")->nullable();
$table->timestamps(); $table->timestamps();
$table->index("commandes_id");
$table->index("produits_id");
$table->index("quantite");
$table->index("prix_vente");
}); });
Schema::table('lignes_commandes', function (Blueprint $table){ Schema::table('lignes_commandes', function (Blueprint $table){
$table->foreign('commandes_id')->references('id')->on('commandes')->onUpdate('cascade')->onDelete('cascade'); $table->foreign('commandes_id')->references('id')->on('commandes')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('produits_id')->references('id')->on('produits')->onUpdate('cascade')->onDelete('set null'); $table->foreign('produits_id')->references('id')->on('produits')->onUpdate('cascade')->onDelete('cascade');
}); });
} }
@ -34,6 +39,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfexists('lignes_commandes'); Schema::dropIfExists('lignes_commandes');
} }
}; };

View File

@ -2,8 +2,8 @@
namespace Database\Seeders; namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
@ -12,8 +12,81 @@ class DatabaseSeeder extends Seeder
* *
* @return void * @return void
*/ */
public function run() public function run() {
{ DB::table('categories')->insert(['id' => 1, 'nom' => 'Basket', 'created_at' => now(), 'updated_at' => now()]);
// \App\Models\User::factory(10)->create(); DB::table('categories')->insert(['id' => 2, 'nom' => 'Bottes', 'created_at' => now(), 'updated_at' => now()]);
DB::table('categories')->insert(['id' => 3, 'nom' => 'Ballerines', 'created_at' => now(), 'updated_at' => now()]);
DB::table('categories')->insert(['id' => 4, 'nom' => 'Sneakers', 'created_at' => now(), 'updated_at' => now()]);
DB::table('clients')->insert(['id' => 1, 'nom' => "Martin", 'prenom' => "Marc", 'adresse' => '{"Pays": "France","Ville": "Marcq-en-baroeul","Adresse": "85 Rue de la Pompe","Code Postal": "59700"}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('clients')->insert(['id' => 2, 'nom' => "Durand", 'prenom' => "Jean", 'adresse' => '{"Pays": "Italie","Ville": "Venise","Adresse": "2049 Place San Polo","Code Postal": "30100"}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('clients')->insert(['id' => 3, 'nom' => "Desmoulin", 'prenom' => "Claire", 'adresse' => '{"Pays": "France","Ville": "Montrouge","Adresse": "67 rue de la Mare aux Carats","Code Postal": "92120"}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('clients')->insert(['id' => 4, 'nom' => "Dubois", 'prenom' => "Martine", 'adresse' => '{"Pays": "Belgique","Ville": "Namur","Adresse": "94 rue de la Boétie","Code Postal": "5004"}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('clients')->insert(['id' => 5, 'nom' => "Fontaine", 'prenom' => "Andrea", 'adresse' => '{"Pays": "France","Ville": "Poitiers","Adresse": "92 rue Victor Hugo","Code Postal": "86000"}']);
DB::table('commandes')->insert(['id' => 1, 'date' => '2023-03-01', 'clients_id' => 1, 'adresse' => '{}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('commandes')->insert(['id' => 2, 'date' => '2023-02-05', 'clients_id' => 2, 'adresse' => '{}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('commandes')->insert(['id' => 3, 'date' => '2023-01-04', 'clients_id' => 3, 'adresse' => '{}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('commandes')->insert(['id' => 4, 'date' => '2023-07-07', 'clients_id' => 1, 'adresse' => '{}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('commandes')->insert(['id' => 5, 'date' => '2023-03-05', 'clients_id' => 4, 'adresse' => '{}', 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 1,'nom' => 'Jordan','taille' => '42','couleur' => 'Blanc','prix' => 154,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 2,'nom' => 'Jordan','taille' => '43','couleur' => 'Noir','prix' => 244,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 3,'nom' => 'Jordan','taille' => '42','couleur' => 'Blanc','prix' => 765,'en_stock' => false, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 4,'nom' => 'Jordan','taille' => '43','couleur' => 'Noir','prix' => 244,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 5,'nom' => 'Air Max','taille' => '42','couleur' => 'Blanc','prix' => 124,'en_stock' => false, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 6,'nom' => 'Air Max','taille' => '43','couleur' => 'Noir','prix' => 530,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 7,'nom' => 'Air Max','taille' => '42','couleur' => 'Blanc','prix' => 250,'en_stock' => false, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 8,'nom' => 'Air Max','taille' => '43','couleur' => 'Noir','prix' => 589,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 9,'nom' => 'FILA','taille' => '42','couleur' => 'Blanc','prix' => 1000,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 10,'nom' => 'FILA','taille' => '43','couleur' => 'Noir','prix' => 100,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 11,'nom' => 'FILA','taille' => '42','couleur' => 'Blanc','prix' => 278,'en_stock' => false, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 12,'nom' => 'FILA','taille' => '43','couleur' => 'Noir','prix' => 864,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 13,'nom' => 'Timberland','taille' => '42','couleur' => 'Blanc','prix' => 90,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 14,'nom' => 'Timberland','taille' => '43','couleur' => 'Noir','prix' => 247,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 15,'nom' => 'Timberland','taille' => '42','couleur' => 'Blanc','prix' => 327,'en_stock' => false, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 16,'nom' => 'Timberland','taille' => '43','couleur' => 'Noir','prix' => 430,'en_stock' => false, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 17,'nom' => 'Marie Jeanes','taille' => '42','couleur' => 'Blanc','prix' => 721,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 18,'nom' => 'Marie Jeanes','taille' => '43','couleur' => 'Noir','prix' => 274,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 19,'nom' => 'Marie Jeanes','taille' => '42','couleur' => 'Blanc','prix' => 564,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits')->insert(['id'=> 20,'nom' => 'Marie Jeanes','taille' => '43','couleur' => 'Noir','prix' => 666,'en_stock' => true, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 1, 'commandes_id' => 2, 'produits_id' => 5, 'quantite' => 1, 'prix_vente' => 193, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 2, 'commandes_id' => 1, 'produits_id' => 6, 'quantite' => 2, 'prix_vente' => 150, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 3, 'commandes_id' => 1, 'produits_id' => 19, 'quantite' => 1, 'prix_vente' => 250, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 4, 'commandes_id' => 2, 'produits_id' => 7, 'quantite' => 1, 'prix_vente' => 114, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 5, 'commandes_id' => 2, 'produits_id' => 13, 'quantite' => 1, 'prix_vente' => 130, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 6, 'commandes_id' => 3, 'produits_id' => 10, 'quantite' => 2, 'prix_vente' => 34, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 7, 'commandes_id' => 3, 'produits_id' => 2, 'quantite' => 3, 'prix_vente' => 244, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 8, 'commandes_id' => 3, 'produits_id' => 9, 'quantite' => 1, 'prix_vente' => 196, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 9, 'commandes_id' => 3, 'produits_id' => 5, 'quantite' => 1, 'prix_vente' => 75, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 10, 'commandes_id' => 4, 'produits_id' => 11, 'quantite' => 1, 'prix_vente' => 136, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 11, 'commandes_id' => 4, 'produits_id' => 4, 'quantite' => 1, 'prix_vente' => 118, 'created_at' => now(), 'updated_at' => now()]);
DB::table('lignes_commandes')->insert(['id' => 12, 'commandes_id' => 5, 'produits_id' => 3, 'quantite' => 2, 'prix_vente' => 183, 'created_at' => now(), 'updated_at' => now()]);
DB::table('produits_categories')->insert(['produits_id' => 1, 'categories_id' => 1]);
DB::table('produits_categories')->insert(['produits_id' => 2, 'categories_id' => 1]);
DB::table('produits_categories')->insert(['produits_id' => 3, 'categories_id' => 1]);
DB::table('produits_categories')->insert(['produits_id' => 4, 'categories_id' => 1]);
DB::table('produits_categories')->insert(['produits_id' => 1, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 2, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 3, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 4, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 5, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 6, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 7, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 8, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 9, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 10, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 11, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 12, 'categories_id' => 4]);
DB::table('produits_categories')->insert(['produits_id' => 13, 'categories_id' => 2]);
DB::table('produits_categories')->insert(['produits_id' => 14, 'categories_id' => 2]);
DB::table('produits_categories')->insert(['produits_id' => 15, 'categories_id' => 2]);
DB::table('produits_categories')->insert(['produits_id' => 16, 'categories_id' => 2]);
DB::table('produits_categories')->insert(['produits_id' => 17, 'categories_id' => 3]);
DB::table('produits_categories')->insert(['produits_id' => 18, 'categories_id' => 3]);
DB::table('produits_categories')->insert(['produits_id' => 19, 'categories_id' => 3]);
DB::table('produits_categories')->insert(['produits_id' => 20, 'categories_id' => 3]);
} }
} }