Skip to content

[10.x] Add support for getting native column type#45598

Closed
hafezdivandari wants to merge 4 commits intolaravel:10.xfrom
hafezdivandari:10.x-patch-2
Closed

[10.x] Add support for getting native column type#45598
hafezdivandari wants to merge 4 commits intolaravel:10.xfrom
hafezdivandari:10.x-patch-2

Conversation

@hafezdivandari
Copy link
Copy Markdown
Contributor

@hafezdivandari hafezdivandari commented Jan 10, 2023

Related to #45487, 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.

This PR changes Schema::getColumnType method to return the actual column type instead of its Doctrine equivalent, also gives us the ability to write integration tests for native column modifying added on #45487. This may also be used on db:table and model:show commands.

After this PR, you'll be able to get eighter data type name or full type definition of the given column:

Schema::getColumnType('products', 'id');           // bigint
Schema::getColumnType('products', 'id', true);     // bigint unsigned
Schema::getColumnType('products', 'status');       // enum
Schema::getColumnType('products', 'status', true); // enum('active','suspended','deleted')
Schema::getColumnType('products', 'name');         // varchar
Schema::getColumnType('products', 'name', true);   // varchar(255)
Schema::getColumnType('products', 'price');        // decimal
Schema::getColumnType('products', 'price', true);  // decimal(8,2)

PS: This PR also cleans up all Schema\Builder classes, many functions were overridden without change.

@taylorotwell
Copy link
Copy Markdown
Member

Honestly I haven't had time to fully review this PR as it's quite large - can you summarize the breaking changes in this PR?

@hafezdivandari
Copy link
Copy Markdown
Contributor Author

hafezdivandari commented Feb 10, 2023

@taylorotwell sure, here is the summarized list:

Added

  • Added the Schema::getColumns($table) method to the schema builder.

Changed

  • Changed the Schema::getColumnType method to return the native DB type instead of its Doctrine equivalent.
  • Changed the processColumnListing method to processColumns method on all query processors.
  • Changed the compileColumnListing method to compileColumns method on all schema grammars.
  • Changed the signature of the compileTableExists method to get required arguments on all schema grammars.
  • Moved createDatabase, dropDatabaseIfExists, getAllTables, and getAllViews methods from MySqlBuilder, PostgresBuilder, SQLiteBuilder and SqlServerBuilder classes to the parent Builder class without BC change.

@taylorotwell
Copy link
Copy Markdown
Member

Tabling this for now.

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