Skip to content

Commit 4486f33

Browse files
authored
Merge pull request #158 from kitloong/feature/laravel10
Fix error
2 parents bef1326 + 8af291f commit 4486f33

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

src/Migration/Blueprint/Support/Stringable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Query\Expression;
66
use Illuminate\Support\Collection;
7+
use Illuminate\Support\Facades\DB;
78
use KitLoong\MigrationsGenerator\Migration\Enum\Space;
89

910
trait Stringable
@@ -60,7 +61,7 @@ public function convertFromAnyTypeToString($value): string
6061
default:
6162
// Wrap with DB::raw();
6263
if ($value instanceof Expression) {
63-
return 'DB::raw("' . $this->escapeDoubleQuote($value) . '")';
64+
return 'DB::raw("' . $this->escapeDoubleQuote(DB::getSchemaGrammar()->getValue($value)) . '")';
6465
}
6566

6667
return (string) $value;

src/Migration/Generator/IndexGenerator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace KitLoong\MigrationsGenerator\Migration\Generator;
44

55
use Illuminate\Support\Collection;
6-
use Illuminate\Support\Facades\DB;
76
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\IndexType;
87
use KitLoong\MigrationsGenerator\Migration\Blueprint\Method;
98
use KitLoong\MigrationsGenerator\Schema\Models\Index;
@@ -54,9 +53,10 @@ public function getChainableIndexes(string $name, Collection $indexes): Collecti
5453
return $carry;
5554
}
5655

57-
if ($index->getLengths()[0] !== null) {
58-
return $carry;
59-
}
56+
// TODO Laravel 10 does not support `$table->index(DB::raw("with_length(16)"))`
57+
// if ($index->getLengths()[0] !== null) {
58+
// return $carry;
59+
// }
6060

6161
$columnName = $index->getColumns()[0];
6262

@@ -120,12 +120,12 @@ private function getColumns(Index $index): array
120120
{
121121
$cols = [];
122122

123-
foreach ($index->getColumns() as $i => $column) {
124-
if ($index->getLengths()[$i] !== null) {
125-
$cols[] = DB::raw($column . '(' . $index->getLengths()[$i] . ')');
126-
continue;
127-
}
128-
123+
foreach ($index->getColumns() as $column) {
124+
// TODO Laravel 10 does not support `$table->index(DB::raw("with_length(16)"))`
125+
// if ($index->getLengths()[$i] !== null) {
126+
// $cols[] = DB::raw($column . '(' . $index->getLengths()[$i] . ')');
127+
// continue;
128+
// }
129129
$cols[] = $column;
130130
}
131131

tests/Feature/FeatureTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function migrateFromTemplate(string $connection, string $templatePath)
109109
File::put($this->getStorageFromPath($file->getBasename()), $content);
110110
File::move(
111111
$this->getStorageFromPath($file->getBasename()),
112-
$this->getStorageFromPath(str_replace('_db_', "_${connection}_", $file->getBasename()))
112+
$this->getStorageFromPath(str_replace('_db_', "_{$connection}_", $file->getBasename()))
113113
);
114114
}
115115

tests/Feature/MySQL57/CommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function testDefaultIndexNames()
185185
'test_index_mysql57_chain_index',
186186
'test_index_mysql57_chain_unique',
187187
'test_index_mysql57_col_multi1_col_multi2_index',
188-
'test_index_mysql57_col_multi1_col_multi2(16)_index',
188+
// 'test_index_mysql57_col_multi1_col_multi2(16)_index',
189189
'test_index_mysql57_col_multi1_col_multi2_unique',
190190
'test_index_mysql57_col_multi_custom1_col_multi_custom2_index',
191191
'test_index_mysql57_col_multi_custom1_col_multi_custom2_unique',
@@ -196,8 +196,8 @@ public function testDefaultIndexNames()
196196
'test_index_mysql57_spatial_index_spatialindex',
197197
'test_index_mysql57_unique_custom_unique',
198198
'test_index_mysql57_unique_unique',
199-
'test_index_mysql57_with_length(16)_index',
200-
'test_index_mysql57_with_length_custom(16)_index',
199+
// 'test_index_mysql57_with_length(16)_index',
200+
// 'test_index_mysql57_with_length_custom(16)_index',
201201
];
202202

203203
if ($this->hasFullText()) {

tests/resources/database/migrations/general/2020_03_21_000000_expected_create_test_index_db_table.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ public function up()
5858
$table->fullText('chain');
5959
}
6060

61-
if (DB::getDriverName() === Driver::MYSQL()->getValue()) {
62-
$table->index(['col_multi1', DB::raw('col_multi2(16)')], 'with_length_multi_custom');
63-
$table->string('with_length');
64-
$table->string('with_length_custom');
65-
$table->index([DB::raw('with_length(16)')]);
66-
$table->index([DB::raw('with_length_custom(16)')], 'with_length_custom');
67-
}
61+
// TODO Laravel 10 does not support `$table->index(DB::raw("with_length(16)"))`
62+
// if (DB::getDriverName() === Driver::MYSQL()->getValue()) {
63+
// $table->index(['col_multi1', DB::raw('col_multi2(16)')], 'with_length_multi_custom');
64+
// $table->string('with_length');
65+
// $table->string('with_length_custom');
66+
// $table->index([DB::raw('with_length(16)')]);
67+
// $table->index([DB::raw('with_length_custom(16)')], 'with_length_custom');
68+
// }
6869
});
6970
}
7071

0 commit comments

Comments
 (0)