Skip to content

Commit 6c8663f

Browse files
author
Fredrick Peter
committed
Migration and Schema fix
1 parent 22c8342 commit 6c8663f

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

src/Collections/Traits/RelatedTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ private function convertMapperOnInit(mixed $items = null)
247247
private function convertOnInit(mixed $items = null)
248248
{
249249
if ($this->unescapeIsObjectWithoutArray) {
250-
return json_decode(json_encode($items), true);
250+
if(!is_bool($items))
251+
return json_decode(json_encode($items), true);
251252
} elseif ($this->isValidJson()) {
252253
return json_decode($items, true);
253254
} elseif (is_array($items) || is_string($items)) {

src/Migrations/Traits/SchemaConfigurationTrait.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function queryForType_and_Length(?array $options = [])
134134
// for enum|set
135135
if(isset($options['values'])){
136136
array_walk($options['values'], function (&$value, $key){
137-
$value = "'{$value}'";
137+
$value = "\'{$value}\'";
138138
});
139139
$values = implode(', ', $options['values']);
140140
$columnDef .= "({$values})";
@@ -225,7 +225,12 @@ protected function queryForDefault(?array $options = [])
225225
{
226226
$columnDef = "";
227227
if (!is_null($options['default'])) {
228-
$columnDef .= " DEFAULT '{$options['default']}'";
228+
// for enum|set
229+
if(isset($options['values'])){
230+
$columnDef .= " DEFAULT \'{$options['default']}\'";
231+
}else{
232+
$columnDef .= " DEFAULT {$options['default']}";
233+
}
229234
}
230235

231236
return $columnDef;

src/Migrations/Traits/TableStructureTrait.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -329,28 +329,13 @@ private function createTriggers()
329329
*/
330330
private function regixifyQuery(?string $formatted)
331331
{
332-
$formattedQuery = '';
333-
$indentationLevel = 0;
334-
$keywords = ['SELECT', 'FROM', 'WHERE', 'JOIN', 'GROUP BY', 'ORDER BY', 'INSERT', 'UPDATE', 'DELETE'];
335-
$lines = explode("\n", $formatted);
332+
// clean string from begining and ending
333+
$formatted = preg_replace("/^[ \t]+|[ \t]+$/m", "", $formatted);
336334

337-
foreach ($lines as $line) {
338-
$trimmedLine = trim($line);
335+
// replace back-slash
336+
$formatted = str_replace('\\', '', $formatted);
339337

340-
if (!empty($trimmedLine)) {
341-
if (in_array(strtoupper($trimmedLine), $keywords)) {
342-
$formattedQuery .= str_repeat(' ', $indentationLevel) . $trimmedLine . "\n";
343-
$indentationLevel++;
344-
} elseif ($trimmedLine === ')') {
345-
$indentationLevel--;
346-
$formattedQuery .= str_repeat(' ', $indentationLevel) . $trimmedLine . "\n";
347-
} else {
348-
$formattedQuery .= str_repeat(' ', $indentationLevel) . $trimmedLine . "\n";
349-
}
350-
}
351-
}
352-
353-
return $formattedQuery;
338+
return $formatted;
354339
}
355340

356341
}

0 commit comments

Comments
 (0)