Skip to content

Commit feee645

Browse files
committed
feat: add special cases to schema diff
1 parent 508a860 commit feee645

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/Schema.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ public static function migrate(string $fileToMigrate): bool
110110
}
111111
}
112112

113+
if ($relationships !== ($lastMigration['relationships'] ?? [])) {
114+
foreach ($relationships as $model) {
115+
if (strpos($model, 'App\Models') === false) {
116+
$model = "App\Models\\$model";
117+
}
118+
119+
$table->foreignIdFor($model);
120+
}
121+
}
122+
113123
$columnsDiff = [];
114124
$staticColumns = [];
115125
$removedColumns = [];
@@ -132,7 +142,17 @@ public static function migrate(string $fileToMigrate): bool
132142
$column = static::getColumnAttributes($columns[$newColumn]);
133143

134144
if (!static::$connection::schema()->hasColumn($tableName, $newColumn)) {
135-
$newCol = $table->{$column['type']}($newColumn);
145+
// [TODO] Add more special cases
146+
if ($column['type'] === 'string') {
147+
$newCol = $table->string(
148+
$newColumn,
149+
$column['length'] ?? 255
150+
);
151+
152+
unset($column['length']);
153+
} else {
154+
$newCol = $table->{$column['type']}($newColumn);
155+
}
136156

137157
unset($column['type']);
138158

@@ -322,7 +342,7 @@ public static function seed(string $fileToSeed): bool
322342
}
323343
}
324344

325-
$parsedData[$key] = $localFakerInstance;
345+
$parsedData[$key] = is_array($localFakerInstance) ? implode('-', $localFakerInstance) : $localFakerInstance;
326346

327347
continue;
328348
}

0 commit comments

Comments
 (0)