-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Corrected SchemaFactoryMakeCommand.php to work with Laravel 11 #15
Conversation
Hello @capimichi 👋 Can you follow the https://www.conventionalcommits.org/en/v1.0.0/ ? |
@TartanLeGrand Here you are, thanks! |
$columnName | ||
); | ||
$name = $columnName; | ||
$default = $connection->select("SELECT COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$tableName' AND COLUMN_NAME = '$columnName'")[0]->COLUMN_DEFAULT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines retrieve the default values and nullability constraints of columns directly from INFORMATION_SCHEMA
.
While this approach works with certain databases like MySQL and MariaDB, it is not universally compatible with all database providers supported by Laravel, such as PostgreSQL and SQL Server.
To improve compatibility with various database management systems, it would be better to use the features of Doctrine DBAL, which provides an abstraction for accessing column metadata in a more generic and provider-independent manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines retrieve the default values and nullability constraints of columns directly from
INFORMATION_SCHEMA
. While this approach works with certain databases like MySQL and MariaDB, it is not universally compatible with all database providers supported by Laravel, such as PostgreSQL and SQL Server. To improve compatibility with various database management systems, it would be better to use the features of Doctrine DBAL, which provides an abstraction for accessing column metadata in a more generic and provider-independent manner.
@TartanLeGrand Good point, i have changed the code to use the more standard Doctrine function to handle columns:
// Use the schema builder to get the columns of the table
$tableColumns = $connection->getSchemaBuilder()->getColumns($tableName);
Thanks!
Changed way to get $default and $notNull, to be more widely compatible
Changed way to get $default and $notNull, to be more widely compatible and tested working
Refactored the code to use the schema builder to retrieve the columns of the table and iterate over each column to find the specific one we're interested in. This change ensures compatibility with Laravel 11 and provides a more widely compatible and tested solution.
Fix this code to work with laravel 11