Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function createComparator(/* ComparatorConfig $config = new ComparatorCon
protected function selectTableNames(string $databaseName): Result
{
$sql = <<<'SQL'
SELECT TABLE_NAME
SELECT CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) AS TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = ?
AND TABLE_TYPE = 'BASE TABLE'
Expand All @@ -358,7 +358,7 @@ protected function selectTableColumns(string $databaseName, ?string $tableName =
$sql = sprintf(
<<<'SQL'
SELECT
c.TABLE_NAME,
CONCAT(c.TABLE_SCHEMA, '.', c.TABLE_NAME) AS TABLE_NAME,
c.COLUMN_NAME AS field,
%s AS type,
c.COLUMN_TYPE,
Expand Down Expand Up @@ -401,7 +401,7 @@ protected function selectIndexColumns(string $databaseName, ?string $tableName =
$sql = sprintf(
<<<'SQL'
SELECT
TABLE_NAME,
CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) AS TABLE_NAME,
NON_UNIQUE AS Non_Unique,
INDEX_NAME AS Key_name,
COLUMN_NAME AS Column_Name,
Expand Down Expand Up @@ -434,7 +434,7 @@ protected function selectForeignKeyColumns(string $databaseName, ?string $tableN
$sql = sprintf(
<<<'SQL'
SELECT
k.TABLE_NAME,
CONCAT(k.TABLE_SCHEMA, '.', k.TABLE_NAME) AS TABLE_NAME,
k.CONSTRAINT_NAME,
k.COLUMN_NAME,
k.REFERENCED_TABLE_NAME,
Expand Down
9 changes: 8 additions & 1 deletion tests/Functional/LockMode/NoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Column;
Expand Down Expand Up @@ -60,7 +61,13 @@ public function setUp(): void

$this->connection2 = DriverManager::getConnection($params);

if ($this->connection2->createSchemaManager()->tableExists('users')) {
if (
$this->connection2->createSchemaManager()->tableExists(
$this->connection2->getDatabasePlatform() instanceof AbstractMySQLPlatform
? 'doctrine_tests.users'
: 'users',
)
) {
return;
}

Expand Down
9 changes: 8 additions & 1 deletion tests/Functional/NamedParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
use Doctrine\DBAL\Schema\Table;
Expand Down Expand Up @@ -163,7 +164,13 @@ public static function ticketProvider(): iterable

protected function setUp(): void
{
if ($this->connection->createSchemaManager()->tableExists('ddc1372_foobar')) {
if (
$this->connection->createSchemaManager()->tableExists(
$this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform
? 'doctrine_tests.ddc1372_foobar'
: 'ddc1372_foobar',
)
) {
return;
}

Expand Down
78 changes: 78 additions & 0 deletions tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,84 @@ public function testSchemaDiffWithCustomColumnTypeWhileDatabaseTypeDiffers(): vo
);
}

public function testListTables(): void
{
$this->createTestTable('list_tables_test');
$tables = $this->schemaManager->listTables();

$table = $this->findTableByName($tables, 'doctrine_tests.list_tables_test');
self::assertNotNull($table);

self::assertTrue($table->hasColumn('id'));
self::assertTrue($table->hasColumn('test'));
self::assertTrue($table->hasColumn('foreign_key_test'));
}

/** @return iterable<string, array{string, int}> */
public static function tableFilterProvider(): iterable
{
yield 'One table' => ['doctrine_tests.filter_test_1', 1];
yield 'Two tables' => ['doctrine_tests.filter_test_', 2];
}

public function testRenameTable(): void
{
$this->createTestTable('old_name');
$this->schemaManager->renameTable('old_name', 'new_name');

self::assertFalse($this->schemaManager->tablesExist(['doctrine_tests.old_name']));
self::assertTrue($this->schemaManager->tablesExist(['doctrine_tests.new_name']));
}

public function testSchemaIntrospection(): void
{
$this->createTestTable('test_table');

$schema = $this->schemaManager->introspectSchema();
self::assertTrue($schema->hasTable('doctrine_tests.test_table'));
}

public function testMigrateSchema(): void
{
$this->createTestTable('table_to_alter');
$this->createTestTable('table_to_drop');

$schema = $this->schemaManager->introspectSchema();

$tableToAlter = $schema->getTable('doctrine_tests.table_to_alter');
$tableToAlter->dropColumn('foreign_key_test');
$tableToAlter->addColumn('number', Types::INTEGER);

$schema->dropTable('doctrine_tests.table_to_drop');

$tableToCreate = $schema->createTable('table_to_create');
$tableToCreate->addColumn('id', Types::INTEGER, ['notnull' => true]);
$tableToCreate->setPrimaryKey(['id']);

$this->schemaManager->migrateSchema($schema);

$schema = $this->schemaManager->introspectSchema();

self::assertTrue($schema->hasTable('doctrine_tests.table_to_alter'));
self::assertFalse($schema->getTable('doctrine_tests.table_to_alter')->hasColumn('foreign_key_test'));
self::assertTrue($schema->getTable('doctrine_tests.table_to_alter')->hasColumn('number'));
self::assertFalse($schema->hasTable('doctrine_tests.table_to_drop'));
self::assertTrue($schema->hasTable('doctrine_tests.table_to_create'));
}

public function testIntrospectReservedKeywordTableViaListTables(): void
{
$this->createReservedKeywordTables();

$tables = $this->schemaManager->listTables();

$user = $this->findTableByName($tables, 'doctrine_tests.user');
self::assertNotNull($user);
self::assertCount(2, $user->getColumns());
self::assertCount(2, $user->getIndexes());
self::assertCount(1, $user->getForeignKeys());
}

public function getExpectedDefaultSchemaName(): ?string
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ public function testIntrospectReservedKeywordTableViaListTables(): void
self::assertCount(1, $user->getForeignKeys());
}

private function createReservedKeywordTables(): void
protected function createReservedKeywordTables(): void
{
$platform = $this->connection->getDatabasePlatform();

Expand Down