-
-
Notifications
You must be signed in to change notification settings - Fork 290
Closed
Description
The migration generator misinterprets a regex-based check constraint using the ~ operator.
Original migration:
public function up(): void
{
Schema::create('organisations', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name_original');
$table->string('parent_id')->nullable();
});
DB::statement("ALTER TABLE organisations ADD CONSTRAINT organisations_parent_id_check CHECK (parent_id IS NULL OR parent_id ~ '^O\\.[0-9]+$')");
}
Constraint created by this migration is (parent_id IS NULL) OR ((parent_id)::text ~ '^O\.[0-9]+$'::text).
Generated migration file:
public function up(): void
{
Schema::create('organisations', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name_original');
$table->enum('parent_id', ['^O\.[0-9]+$'])->nullable();
});
}
As you can see, parent_id becomes enum and constraint check created by this migration compares the string value of parent_id to the literal string O\.[0-9]+$ — (parent_id IS NULL) OR ((parent_id)::text ='^O\.[0-9]+$'::text).
Details:
- DB: postgres (PostgreSQL) 14.18
- Laravel Version: 12.0
- PHP Version: PHP 8.3.22
- Migrations Generator Version: 7.1.2
kitloongCopilot