This content originally appeared on DEV Community and was authored by Luigui Moreno
Acá un script para cuando se actualize Laravel de la version 10 a la 11, este script permite encontrar los archivos a donde esta la columna de una tabla a la que se le han hecho cambios
Here's a script for when Laravel is updated from version 10 to 11. This script allows you to find the files where the column of a table that has undergone changes is located.
<?php
function searchMigrations($directory, $tableName, $columnName) {
$pattern = '/(?:create|table)\s*\(\s*[\'"]' . preg_quote($tableName, '/') . '[\'"].*?\$table.*?[\'"]' . preg_quote($columnName, '/') . '[\'"\)]/is';
$migrations = glob($directory . '/*_*.php');
$matches = [];
foreach ($migrations as $migration) {
$content = file_get_contents($migration);
if (preg_match($pattern, $content)) {
$matches[] = $migration;
}
}
return $matches;
}
// Verificar si se proporcionaron los argumentos necesarios
if ($argc < 3) {
echo "Uso: php " . $argv[0] . " <nombre_tabla> <nombre_columna>\n";
echo "Ejemplo: php " . $argv[0] . " pedidos user_id\n";
exit(1);
}
$migrationsDir = __DIR__ . '/database/migrations';
$tableName = $argv[1];
$columnName = $argv[2];
echo "Buscando migraciones para la tabla '$tableName' y la columna '$columnName'...\n\n";
$results = searchMigrations($migrationsDir, $tableName, $columnName);
if (empty($results)) {
echo "No se encontraron migraciones que coincidan con los criterios.\n";
} else {
foreach ($results as $file) {
echo realpath($file) . "\n";
}
echo "\nTotal de migraciones encontradas: " . count($results) . "\n";
}
This content originally appeared on DEV Community and was authored by Luigui Moreno
Luigui Moreno | Sciencx (2024-08-28T15:27:38+00:00) Laravel upgrade 10 to 11 Modifying Columns change. Retrieved from https://www.scien.cx/2024/08/28/laravel-upgrade-10-to-11-modifying-columns-change/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.