Skip to content
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

Merged
merged 4 commits into from
Jul 13, 2024

Conversation

capimichi
Copy link

Fix this code to work with laravel 11

@TartanLeGrand
Copy link
Collaborator

Hello @capimichi 👋 Can you follow the https://www.conventionalcommits.org/en/v1.0.0/ ?

@capimichi capimichi changed the title Fix SchemaFactoryMakeCommand.php for laravel 11 fix: Corrected SchemaFactoryMakeCommand.php to work with Laravel 11 Jul 12, 2024
@capimichi
Copy link
Author

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;
Copy link
Collaborator

@TartanLeGrand TartanLeGrand Jul 12, 2024

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.

Copy link
Author

@capimichi capimichi Jul 13, 2024

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.
@TartanLeGrand TartanLeGrand merged commit b0f57cf into Nova-Edge:main Jul 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants