Update the database schema

This commit is contained in:
Antoine Le Gonidec 2024-07-16 12:04:08 +02:00
parent 2ddccd9c41
commit 6084247248
Signed by: vv221
GPG key ID: 636B78F91CEB80D8
3 changed files with 92 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<?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 CreateCustomersGroupsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('customers_groups', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
// Include a "mailbox_id" column in the customers groups table, linking each group entry to a specific mailbox.
$table
->integer('mailbox_id')
->unsigned();
$table
->foreign('mailbox_id')
->references('id')
->on('mailboxes')
// On mailbox deletion, delete all customers group entries that are linked to it.
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('customers_groups');
}
}

View file

@ -0,0 +1,49 @@
<?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');
}
}

View file

@ -21,6 +21,7 @@ class MMFCustomersGroupsServiceProvider extends ServiceProvider {
*/ */
public function boot() { public function boot() {
$this->registerConfig(); $this->registerConfig();
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
} }
/** /**