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

[11.x] Remove Doctrine DBAL #48864

Merged
merged 61 commits into from Jan 9, 2024
Merged

Conversation

hafezdivandari
Copy link
Contributor

@hafezdivandari hafezdivandari commented Oct 31, 2023

Finally, this PR removes Doctrine DBAL from the framework. πŸŽ‰

New Features / Enhancements

  • Removes every single usage of doctrine/dbal from the framework ⚑
  • Adds native column modifying for SQLite πŸš€
  • Adds native column renaming for legacy MySQL (< 8.0.3) and MariaDB (<10.5.2) πŸ‘
  • Adds native index renaming on SQLite
  • Adds collation column modifier on SQLite
  • Adds collation to Schema::getColumns() on SQLite (was always null before)
  • Includes generated and hidden columns when retrieving columns using Schema::getColumns() on SQLite
  • Rewrites db:show, db:table, and model:show artisan commands to use native schema methods ✨
  • Enhances number formatting on db:show and db:table commands using Number helper class
  • Adds user-defined types to db:show artisan command (PostgreSQL only)
  • Adds schema to db:show artisan command (PostgreSQL and SQL Server only)
  • Adds DB::getServerVersion() to get database version

Notes

  1. Legacy MySQL (< 8.0) and MariaDB (< 10.5.2) don't have alter table rename column command, so we're retrieving column's attributes and use alter table change column command instead, just like Doctrine DBAL, but also with support for all types including enum, geometry, etc. However, renaming generated columns (using storedAs($expression) and virtualAs($spression)) on these legacy DBs using $table->renameColumn() are not supported, but there is a workaround for this using ->renameTo()->change() Fixed on [11.x] Add support for modifying generated columnsΒ #50329.

  2. Due to limitations of SQLite, modifying a column on a table that has a generated column (using storedAs($expression) and virtualAs($spression)) is partially supported, it's better than Doctrine DBAL that doesn't support these at all, but it's still not fully supported. A workaround is to also redeclare any existing generated column with change() at the end. Fixed on [11.x] Add support for modifying generated columnsΒ #50329

Check List

Changes

  • Adds DB::getServerVersion() method
  • Removes Schema::$alwaysUsesNativeSchemaOperationsIfPossible class property
  • Removes Schema::useNativeSchemaOperationsIfPossible() method
  • Removes DB::getDoctrineConnection() and the whole \Illuminate\Database\PDO directory
  • Removes DB::usingNativeSchemaOperations() method
  • Removes DB::isDoctrineAvailable() method
  • Removes DB::getDoctrineColumn() method
  • Removes DB::getDoctrineSchemaManager() method
  • Removes DB::registerDoctrineType() method (both \Illuminate\Database\DatabaseManager::registerDoctrineType() and \Illuminate\Database\Connection::registerDoctrineType() methods)
  • Removes database.dbal.types config property
  • Removes \Illuminate\Database\DBAL\TimestampType class
  • Removes \Illuminate\Database\Schema\Grammars\ChangeColumn class
  • Removes \Illuminate\Database\Schema\Grammars\RenameColumn class
  • Removes \Illuminate\Database\Schema\Grammars\Grammar::getDoctrineTableDiff() method

Upgrade Guide

SQLite 3.35.0+

If your application is utilizing an SQLite database, you should update SQLite to 3.35.0+ (laravel/docs#9017).

Removal of Doctrine DBAL

You may remove doctrine/dbal composer dependency.

composer remove doctrine/dbal

Modifying Columns

As already noted on Laravel 10.x docs, When modifying a column, you must explicitly include all of the modifiers you want to keep on the column definition - any missing attribute will be dropped. For example, to retain the unsigned, default, and comment attributes, you must call each modifier explicitly when changing the column:

Schema::table('users', function (Blueprint $table) {
    $table->integer('votes')->unsigned()->default(1)->comment('my comment')->change();
});

Schema builder getColumnType() method

The Schema::getColumnType() method now always returns actual database type of the given column, not the doctrine equivalent type, even if you have doctrine/dbal installed.

Registering Custom Doctrine Types

As we are not using Doctrine DBAL for modifying/renaming columns, registering custom doctrine types are not supported anymore. The database.dbal.types config key and DB::registerDoctrineType() method are removed.

.github/workflows/databases.yml Outdated Show resolved Hide resolved
@juanparati
Copy link
Contributor

If you are replacing DBAL in 11.x, please consider to take a look in order to find possible improvement ideas:

@hafezdivandari
Copy link
Contributor Author

hafezdivandari commented Dec 27, 2023

I also removed DB::getDoctrineConnection() and the whole \Illuminate\Database\PDO directory in a single commit 5e99d96

I think it wasn't a good practice to keep this on the core, as we have no use case for this on the framework, and some contributions using this method may mistakenly get merge to the core in the future.

However you may revert this commit if you prefer to keep this method for any reason.

@taylorotwell taylorotwell merged commit 9ccf003 into laravel:master Jan 9, 2024
20 checks passed
@taylorotwell
Copy link
Member

Thanks!

@driesvints
Copy link
Member

Thanks @hafezdivandari!

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.

None yet

8 participants