Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 19 additions & 3 deletions src/Dacapo/Domain/Schema/IndexModifier/IndexModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ final class IndexModifier
* @param array<int, string> $columns
* @param string|null $name = null
* @param string|null $algorithm = null
* @param string|null $language = null
*/
private function __construct(
private IndexModifierType $type,
private array $columns,
private ?string $name = null,
private ?string $algorithm = null,
private ?string $language = null,
) {
}

Expand All @@ -39,12 +41,14 @@ public static function factory(array $attributes): self
$columns = is_string($attributes['columns']) ? self::parse($attributes['columns']) : $attributes['columns'];
$name = $attributes['name'] ?? null;
$algorithm = $attributes['algorithm'] ?? null;
$language = $attributes['language'] ?? null;

return new self(
$indexType,
$columns,
$name,
$algorithm
$algorithm,
$language
);
}

Expand All @@ -54,10 +58,10 @@ public static function factory(array $attributes): self
public function createIndexMigrationUpMethod(): string
{
if ($this->hasArgs()) {
return '$table->' . sprintf('%s(%s, %s);', $this->type->getUpMethodName(), $this->getColumns(), $this->makeArgs());
return '$table->' . sprintf('%s(%s, %s)%s;', $this->type->getUpMethodName(), $this->getColumns(), $this->makeArgs(), $this->makeLanguage());
}

return '$table->' . sprintf('%s(%s);', $this->type->getUpMethodName(), $this->getColumns());
return '$table->' . sprintf('%s(%s)%s;', $this->type->getUpMethodName(), $this->getColumns(), $this->makeLanguage());
}

/**
Expand Down Expand Up @@ -114,6 +118,18 @@ private function makeArgs(): string
throw new InvalidArgumentException('Has no args.');
}

/**
* @return string
*/
private function makeLanguage(): string
{
if ($this->language === null) {
return '';
}

return sprintf("->language('%s')", $this->language);
}

/**
* @param string $columns
* @return array<int, string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace UcanLab\LaravelDacapo\Dacapo\Domain\Schema\IndexModifier\IndexModifierType;

final class FullTextType implements IndexModifierType
{
public function __construct()
{
}

public function getUpMethodName(): string
{
return 'fullText';
}

public function getDownMethodName(): string
{
return 'dropFullText';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class IndexModifierTypeFactory
'primary' => PrimaryType::class,
'spatialIndex' => SpatialIndexType::class,
'unique' => UniqueType::class,
'fullText' => FullTextType::class,
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('example5', function (Blueprint $table) {
$table->bigIncrements('id');
$table->longText('body1');
$table->longText('body2');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('example5');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('example5', function (Blueprint $table) {
$table->fullText('body1');
$table->fullText('body2', 'example5_body2_fullText');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('example5', function (Blueprint $table) {
$table->dropFullText(['body1']);
$table->dropFullText('example5_body2_fullText');
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ example4:
- columns: name, email
type: index
name: users_name_index

example5:
columns:
id: bigIncrements
body1: longText
body2: longText
indexes:
- columns: body1
type: fullText
- columns: body2
type: fullText
name: example5_body2_fullText