freescout-customers-groups/Database/Migrations/2024_07_16_115333_link_customers_to_groups.php

49 lines
1.1 KiB
PHP

<?php
/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class LinkCustomersToGroups extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('customers_group_customers', function (Blueprint $table) {
// Set a link between customers groups and customers.
$table
->integer('customers_group_id')
->unsigned();
$table
->foreign('customers_group_id')
->references('id')
->on('customers_groups')
->onDelete('cascade');
$table
->integer('customer_id')
->unsigned();
$table
->foreign('customer_id')
->references('id')
->on('customers')
->onDelete('cascade');
// Prevent the inclusion of duplicated entries.
$table->unique(['customers_group_id', 'customer_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('customers_group_customers');
}
}