From a5761d4187abea654cb422c2f70054a880ffd2e0 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 9 Dec 2020 20:20:24 -0700 Subject: [PATCH 001/403] Added registerDBALTypes() function to DatabaseServiceProvider --- .../Database/DatabaseServiceProvider.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Illuminate/Database/DatabaseServiceProvider.php b/src/Illuminate/Database/DatabaseServiceProvider.php index 49ea50f19556..8433ea982bd1 100755 --- a/src/Illuminate/Database/DatabaseServiceProvider.php +++ b/src/Illuminate/Database/DatabaseServiceProvider.php @@ -2,6 +2,7 @@ namespace Illuminate\Database; +use Doctrine\DBAL\Types\Type; use Faker\Factory as FakerFactory; use Faker\Generator as FakerGenerator; use Illuminate\Contracts\Queue\EntityResolver; @@ -45,6 +46,30 @@ public function register() $this->registerEloquentFactory(); $this->registerQueueableEntityResolver(); + + $this->registerDBALTypes(); + } + + /** + * Add any custom types to the DBAL library. + * + * @return void + */ + protected function registerDBALTypes() + { + if (! class_exists(Type::class)) { + return; + } + + $types = config('database.dbal.types'); + + if (! is_array($types)) { + return; + } + + foreach ($types as $typeName => $typeClassDefinition) { + \Schema::registerCustomDoctrineType($typeClassDefinition, $typeName, $typeName); + } } /** From 382445f8487de45a05ebe121837f917b92560a97 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sat, 12 Dec 2020 19:29:28 -0700 Subject: [PATCH 002/403] Add types directly; Timestamp for sqlite & mysql working --- .../Database/DBAL/TimestampType.php | 91 +++++++++++++++++++ .../Database/DatabaseServiceProvider.php | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/Illuminate/Database/DBAL/TimestampType.php diff --git a/src/Illuminate/Database/DBAL/TimestampType.php b/src/Illuminate/Database/DBAL/TimestampType.php new file mode 100644 index 000000000000..dbc205f0ed09 --- /dev/null +++ b/src/Illuminate/Database/DBAL/TimestampType.php @@ -0,0 +1,91 @@ +getName(); + + // See https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html + switch ($name) { + case 'mssql': + return $this->getMSSQLPlatformSQLDeclaration($fieldDeclaration); + + case 'mysql': + case 'mysql2': + return $this->getMySQLPlatformSQLDeclaration($fieldDeclaration); + + case 'postgresql': + case 'pgsql': + case 'postgres': + return $this->getPostgreSQLPlatformSQLDeclaration($fieldDeclaration); + + case 'sqlite': + case 'sqlite3': + return $this->getSqlitePlatformSQLDeclaration($fieldDeclaration); + + default: + throw new DBALException('Invalid platform: '.$name); + } + } + + // https://docs.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15 + // timestamp in MSSQL is not a field for storing datetime data + protected function getMSSQLPlatformSQLDeclaration(array $fieldDeclaration) + { + $columnType = 'DATETIME'; + + if ($fieldDeclaration['precision']) { + $columnType = 'DATETIME2('.$fieldDeclaration['precision'].')'; + } + + return $columnType; + } + + protected function getMySQLPlatformSQLDeclaration(array $fieldDeclaration) + { + $columnType = 'TIMESTAMP'; + + if ($fieldDeclaration['precision']) { + $columnType = 'TIMESTAMP('.$fieldDeclaration['precision'].')'; + } + + $notNull = $fieldDeclaration['notnull'] ?? false; + + if (! $notNull) { + return $columnType.' NULL'; + } + + return $columnType; + } + + protected function getPostgreSQLPlatformSQLDeclaration(array $fieldDeclaration) + { + $columnType = 'TIMESTAMP('.(int) $fieldDeclaration['precision'].')'; + + return $columnType; + } + + /** + * Laravel creates timestamps as datetime in SQLite. + * + * SQLite does not store microseconds without custom hacks. + */ + protected function getSqlitePlatformSQLDeclaration(array $fieldDeclaration) + { + $columnType = 'DATETIME'; + + return $columnType; + } +} diff --git a/src/Illuminate/Database/DatabaseServiceProvider.php b/src/Illuminate/Database/DatabaseServiceProvider.php index 8433ea982bd1..0026e0c001c8 100755 --- a/src/Illuminate/Database/DatabaseServiceProvider.php +++ b/src/Illuminate/Database/DatabaseServiceProvider.php @@ -68,7 +68,7 @@ protected function registerDBALTypes() } foreach ($types as $typeName => $typeClassDefinition) { - \Schema::registerCustomDoctrineType($typeClassDefinition, $typeName, $typeName); + Type::addType($typeName, $typeClassDefinition); } } From cff37055cbf031109ae769e8fd6ad1951be47aa6 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 13 Dec 2020 17:52:02 -0700 Subject: [PATCH 003/403] Update src/Illuminate/Database/DatabaseServiceProvider.php Use default config value instead of validating config Co-authored-by: Dries Vints --- src/Illuminate/Database/DatabaseServiceProvider.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Illuminate/Database/DatabaseServiceProvider.php b/src/Illuminate/Database/DatabaseServiceProvider.php index 0026e0c001c8..c16b00c85bc3 100755 --- a/src/Illuminate/Database/DatabaseServiceProvider.php +++ b/src/Illuminate/Database/DatabaseServiceProvider.php @@ -61,11 +61,7 @@ protected function registerDBALTypes() return; } - $types = config('database.dbal.types'); - - if (! is_array($types)) { - return; - } + $types = config('database.dbal.types', []); foreach ($types as $typeName => $typeClassDefinition) { Type::addType($typeName, $typeClassDefinition); From 810047e1f184f8a4def372885591e4fbb6996b51 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 14 Dec 2020 09:41:00 -0600 Subject: [PATCH 004/403] formatting --- .../Database/DBAL/TimestampType.php | 82 +++++++++++-------- .../Database/DatabaseServiceProvider.php | 41 +++++----- 2 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/Illuminate/Database/DBAL/TimestampType.php b/src/Illuminate/Database/DBAL/TimestampType.php index dbc205f0ed09..0ab733cfe520 100644 --- a/src/Illuminate/Database/DBAL/TimestampType.php +++ b/src/Illuminate/Database/DBAL/TimestampType.php @@ -8,52 +8,42 @@ class TimestampType extends Type { - public function getName() - { - return 'timestamp'; - } - + /** + * {@inheritdoc} + */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { $name = $platform->getName(); - // See https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html switch ($name) { - case 'mssql': - return $this->getMSSQLPlatformSQLDeclaration($fieldDeclaration); - case 'mysql': case 'mysql2': - return $this->getMySQLPlatformSQLDeclaration($fieldDeclaration); + return $this->getMySqlPlatformSQLDeclaration($fieldDeclaration); case 'postgresql': case 'pgsql': case 'postgres': - return $this->getPostgreSQLPlatformSQLDeclaration($fieldDeclaration); + return $this->getPostgresPlatformSQLDeclaration($fieldDeclaration); + + case 'mssql': + return $this->getSqlServerPlatformSQLDeclaration($fieldDeclaration); case 'sqlite': case 'sqlite3': - return $this->getSqlitePlatformSQLDeclaration($fieldDeclaration); + return $this->getSQLitePlatformSQLDeclaration($fieldDeclaration); default: throw new DBALException('Invalid platform: '.$name); } } - // https://docs.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15 - // timestamp in MSSQL is not a field for storing datetime data - protected function getMSSQLPlatformSQLDeclaration(array $fieldDeclaration) - { - $columnType = 'DATETIME'; - - if ($fieldDeclaration['precision']) { - $columnType = 'DATETIME2('.$fieldDeclaration['precision'].')'; - } - - return $columnType; - } - - protected function getMySQLPlatformSQLDeclaration(array $fieldDeclaration) + /** + * Get the SQL declaration for MySQL. + * + * @param array $fieldDeclaration + * @return string + */ + protected function getMySqlPlatformSQLDeclaration(array $fieldDeclaration) { $columnType = 'TIMESTAMP'; @@ -70,22 +60,46 @@ protected function getMySQLPlatformSQLDeclaration(array $fieldDeclaration) return $columnType; } - protected function getPostgreSQLPlatformSQLDeclaration(array $fieldDeclaration) + /** + * Get the SQL declaration for PostgreSQL. + * + * @param array $fieldDeclaration + * @return string + */ + protected function getPostgresPlatformSQLDeclaration(array $fieldDeclaration) { - $columnType = 'TIMESTAMP('.(int) $fieldDeclaration['precision'].')'; + return 'TIMESTAMP('.(int) $fieldDeclaration['precision'].')'; + } - return $columnType; + /** + * Get the SQL declaration for SQL Server. + * + * @param array $fieldDeclaration + * @return string + */ + protected function getSqlServerPlatformSQLDeclaration(array $fieldDeclaration) + { + return $fieldDeclaration['precision'] ?? false + ? 'DATETIME2('.$fieldDeclaration['precision'].')' + : 'DATETIME'; } /** - * Laravel creates timestamps as datetime in SQLite. + * Get the SQL declaration for SQLite. * - * SQLite does not store microseconds without custom hacks. + * @param array $fieldDeclaration + * @return string */ - protected function getSqlitePlatformSQLDeclaration(array $fieldDeclaration) + protected function getSQLitePlatformSQLDeclaration(array $fieldDeclaration) { - $columnType = 'DATETIME'; + return 'DATETIME'; + } - return $columnType; + /** + * {@inheritdoc} + */ + public function getName() + { + return 'timestamp'; } } diff --git a/src/Illuminate/Database/DatabaseServiceProvider.php b/src/Illuminate/Database/DatabaseServiceProvider.php index c16b00c85bc3..72f131d0db49 100755 --- a/src/Illuminate/Database/DatabaseServiceProvider.php +++ b/src/Illuminate/Database/DatabaseServiceProvider.php @@ -42,30 +42,9 @@ public function register() Model::clearBootedModels(); $this->registerConnectionServices(); - $this->registerEloquentFactory(); - $this->registerQueueableEntityResolver(); - - $this->registerDBALTypes(); - } - - /** - * Add any custom types to the DBAL library. - * - * @return void - */ - protected function registerDBALTypes() - { - if (! class_exists(Type::class)) { - return; - } - - $types = config('database.dbal.types', []); - - foreach ($types as $typeName => $typeClassDefinition) { - Type::addType($typeName, $typeClassDefinition); - } + $this->registerDoctrineTypes(); } /** @@ -129,4 +108,22 @@ protected function registerQueueableEntityResolver() return new QueueEntityResolver; }); } + + /** + * Register custom types with the Doctrine DBAL library. + * + * @return void + */ + protected function registerDoctrineTypes() + { + if (! class_exists(Type::class)) { + return; + } + + $types = $this->app['config']->get('database.dbal.types', []); + + foreach ($types as $name => $class) { + Type::addType($name, $class); + } + } } From 94171f04f1aaa79bdcf1f0f9e076f276cd46608d Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 15 Dec 2020 00:33:42 +0100 Subject: [PATCH 005/403] Update phpunit.xml.dist (#35605) --- phpunit.xml.dist | 8 -------- 1 file changed, 8 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3cb5a6c6ba63..bb20f5f6ded1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -17,14 +17,6 @@ ./tests - - - ./src - - - ./src/ - -