1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
4
|
|
|
|
5
|
|
|
use Modelarium\Exception\Exception; |
6
|
|
|
use Modelarium\Laravel\Targets\MigrationGenerator; |
7
|
|
|
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface; |
8
|
|
|
use Modelarium\Laravel\Targets\MigrationCodeFragment; |
9
|
|
|
use Modelarium\Parser; |
10
|
|
|
|
11
|
|
|
class MigrationIndexDirective implements MigrationDirectiveInterface |
12
|
|
|
{ |
13
|
1 |
|
public static function processMigrationTypeDirective( |
14
|
|
|
MigrationGenerator $generator, |
15
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
16
|
|
|
): void { |
17
|
1 |
|
$indexFields = Parser::getDirectiveArgumentByName($directive, 'fields'); |
18
|
|
|
|
19
|
1 |
|
if (!count($indexFields)) { |
20
|
|
|
throw new Exception("You must provide at least one field to an index"); |
21
|
|
|
} |
22
|
1 |
|
$generator->createCode[] ='$table->index("' . implode('", "', $indexFields) .'");'; |
|
|
|
|
23
|
1 |
|
} |
24
|
|
|
|
25
|
|
|
public static function processMigrationFieldDirective( |
26
|
|
|
MigrationGenerator $generator, |
27
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
28
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
29
|
|
|
MigrationCodeFragment $code |
30
|
|
|
): void { |
31
|
|
|
$code->appendExtraLine('$table->index("' . $field->name . '");'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function processMigrationRelationshipDirective( |
35
|
|
|
MigrationGenerator $generator, |
36
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
37
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
38
|
|
|
MigrationCodeFragment $code |
39
|
|
|
): void { |
40
|
|
|
$code->appendExtraLine('$table->index("' . $field->name . '");'); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|