Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique constraint to project name #2099

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions database/migrations/2024_03_22_031040_project_unique_name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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
{
// Add the unique constraint.
// Note: This migration will fail if two projects with the same name exist in the database.
// Since having two projects with the same name is undefined behavior, and should
// never happen in theory, we defer to the CDash administrator to decide what to do.
// The CDash UI prevents duplicate projects from being created, so this should never
// occur under normal circumstances.
Schema::table('project', function (Blueprint $table) {
$table->unique('name');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('project', function (Blueprint $table) {
$table->dropUnique(['name']);
});
}
};