-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[10.x] Get columns of a table #48357
Conversation
@hafezdivandari I am curious about the third point if I haven't add Am i missing something here? |
@morloderex These are separated matters, you have to call
|
Previous attempt (PR #45598) was a breaking change and tabled a few days before Laravel 10 release. This PR has more features than the previous one and is not a breaking change.
Usage
Schema::getColumns()
name
(string
): Name of the columntype_name
(string
): Type nametype
(string
): Full definition of the column typecollation
(?string
): Collation of the columnnullable
(boolean
): Is column nullable?default
(?string
): Default expression of the column if definedauto_increment
(boolean
): Does column auto increment?comment
(?string
): Comment of the column if existsgeneration
(null|array
) (added on Laravel 11 via [11.x] Add support for modifying generated columns #50329):type
(string
): Generation type:'stored'
or'virtual'
.expression
(string
): Generation expression.Changes
This PR:
Adds a new
Schema::getColumns()
:Currently, we are using
doctrine/dbal
to get columns of a table and their attributes, for example onmodel:show
artisan command. This PR addsSchema::getColumns($table)
for MySQL, PostgreSQL, SQLite and SQL Server without Doctrine DBAL type mapping issues and full support for all native types. This function returns a list of columns and their attributes:Adds native support for
Schema::getColumnType()
:Currently we are using Doctrine DBAL to get column type using
Schema::getColumnType
method. DBAL maps every native column type to its Doctrine type equivalent and doesn't support many column types used by Laravel on different databases.After this PR you won't need to install
doctrine/dbal
to get type of a column, you'll be able to get eighter data type name or full type definition of the given column:Just like [10.x] Add support for native column modifying #45487, if you have already installed
doctrine/dbal
, you have to callSchema::useNativeSchemaOperationsIfPossible()
method within theboot
method of yourApp\Providers\AppServiceProvider
class to be able to use native schema operations.Deprecates a few functions:
This PR makes
Schema::getColumnListing()
function to use newly addedSchema::getColumns()
method under the hood, so we don't need any of the following functions any more. This PR deprecates:\Illuminate\Database\Query\Processors\Processor::processColumnListing
\Illuminate\Database\Query\Processors\MySqlProcessor::processColumnListing
\Illuminate\Database\Query\Processors\PostgresProcessor::processColumnListing
\Illuminate\Database\Query\Processors\SQLiteProcessor::processColumnListing
\Illuminate\Database\Query\Processors\SqlServerProcessor::processColumnListing
\Illuminate\Database\Schema\Grammars\MySqlGrammar::compileColumnListing
\Illuminate\Database\Schema\Grammars\PostgresGrammar::compileColumnListing
\Illuminate\Database\Schema\Grammars\SQLiteGrammar::compileColumnListing
\Illuminate\Database\Schema\Grammars\SqlServerGrammar::compileColumnListing