1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
4
|
|
|
|
5
|
|
|
use Modelarium\Exception\DirectiveException; |
6
|
|
|
use Modelarium\Exception\Exception; |
7
|
|
|
use Modelarium\Laravel\Targets\MigrationGenerator; |
8
|
|
|
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface; |
9
|
|
|
use Modelarium\Laravel\Targets\MigrationCodeFragment; |
10
|
|
|
use Modelarium\Parser; |
11
|
|
|
|
12
|
|
|
class MigrationAlterTableDirective implements MigrationDirectiveInterface |
13
|
|
|
{ |
14
|
1 |
|
public static function processMigrationTypeDirective( |
15
|
|
|
MigrationGenerator $generator, |
16
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
17
|
|
|
): void { |
18
|
1 |
|
$values = Parser::getDirectiveArgumentByName($directive, 'values'); |
19
|
|
|
|
20
|
1 |
|
foreach ($values as $v) { |
21
|
1 |
|
$generator->postCreateCode[] = "DB::statement('ALTER TABLE " . |
22
|
1 |
|
$generator->getTableName() . ' ' . |
23
|
1 |
|
$v . |
24
|
1 |
|
"');"; |
25
|
|
|
} |
26
|
1 |
|
} |
27
|
|
|
|
28
|
|
|
public static function processMigrationFieldDirective( |
29
|
|
|
MigrationGenerator $generator, |
30
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
31
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
32
|
|
|
MigrationCodeFragment $code |
33
|
|
|
): void { |
34
|
|
|
throw new DirectiveException("migrationAlterTable only applies to type"); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function processMigrationRelationshipDirective( |
38
|
|
|
MigrationGenerator $generator, |
39
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
40
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
41
|
|
|
MigrationCodeFragment $code |
42
|
|
|
): void { |
43
|
|
|
throw new DirectiveException("migrationAlterTable only applies to type"); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|