Laravel upgrade 10 to 11 Modifying Columns change

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 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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Laravel upgrade 10 to 11 Modifying Columns change." Luigui Moreno | Sciencx - Wednesday August 28, 2024, https://www.scien.cx/2024/08/28/laravel-upgrade-10-to-11-modifying-columns-change/
HARVARD
Luigui Moreno | Sciencx Wednesday August 28, 2024 » Laravel upgrade 10 to 11 Modifying Columns change., viewed ,<https://www.scien.cx/2024/08/28/laravel-upgrade-10-to-11-modifying-columns-change/>
VANCOUVER
Luigui Moreno | Sciencx - » Laravel upgrade 10 to 11 Modifying Columns change. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/28/laravel-upgrade-10-to-11-modifying-columns-change/
CHICAGO
" » Laravel upgrade 10 to 11 Modifying Columns change." Luigui Moreno | Sciencx - Accessed . https://www.scien.cx/2024/08/28/laravel-upgrade-10-to-11-modifying-columns-change/
IEEE
" » Laravel upgrade 10 to 11 Modifying Columns change." Luigui Moreno | Sciencx [Online]. Available: https://www.scien.cx/2024/08/28/laravel-upgrade-10-to-11-modifying-columns-change/. [Accessed: ]
rf:citation
» Laravel upgrade 10 to 11 Modifying Columns change | Luigui Moreno | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.