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

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

Closed
wants to merge 4 commits into from
Closed

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

wants to merge 4 commits into from

Conversation

hafezdivandari
Copy link
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
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
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
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