Skip to content

Commit

Permalink
Fix constraints based on self
Browse files Browse the repository at this point in the history
  • Loading branch information
NastuzziSamy committed Jul 3, 2021
1 parent 75452f8 commit bec1636
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion resources/views/migration/block.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
Schema::{{ $type === 'create' ? $type : 'table' }}({!! json_encode($table) !!}, function (Blueprint {{ '$table' }}) {
@foreach ($blocks as $block)
@foreach ($blocks as $key => $block)
@if ($key === 'self_constraints') });

Schema::table({!! json_encode($table) !!}, function (Blueprint {{ '$table' }}) {
@include('laramore::migration.partials.commands', ['commands' => $block])
@else
@if (!$loop->first)

@endif
@include('laramore::migration.partials.commands', ['commands' => $block])
@endif
@endforeach
});
14 changes: 12 additions & 2 deletions src/Migrations/MetaNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,19 @@ public function getCommands(): array
'fields' => [],
'constraints' => [],
'indexes' => [],
'self_constraints' => [],
];

foreach ($fieldCommands as $command) {
$commands[($command instanceof IsADropCommand ? 'drop_fields' : 'fields')][] = $command;
}

foreach ($constraintCommands as $command) {
$commands[($command instanceof IsADropCommand ? 'drop_constraints' : 'constraints')][] = $command;
if (! ($command instanceof IsADropCommand) && $command->getTableName() === $command->getProperties()['on']) {
$commands['self_constraints'][] = $command;
} else {
$commands[($command instanceof IsADropCommand ? 'drop_constraints' : 'constraints')][] = $command;
}
}

foreach ($indexCommands as $command) {
Expand Down Expand Up @@ -208,14 +213,19 @@ public function getReverseCommands(): array
'fields' => [],
'constraints' => [],
'indexes' => [],
'self_constraints' => [],
];

foreach ($fieldCommands as $command) {
$commands[($command instanceof IsADropCommand ? 'drop_fields' : 'fields')][] = $command;
}

foreach ($constraintCommands as $command) {
$commands[($command instanceof IsADropCommand ? 'drop_constraints' : 'constraints')][] = $command;
if (! ($command instanceof IsADropCommand) && $command->getTableName() === $command->getProperties()['on']) {
$commands['self_constraints'][] = $command;
} else {
$commands[($command instanceof IsADropCommand ? 'drop_constraints' : 'constraints')][] = $command;
}
}

foreach ($indexCommands as $command) {
Expand Down

0 comments on commit bec1636

Please sign in to comment.