Skip to content

Commit

Permalink
add $filterAssetNames to get assert tables
Browse files Browse the repository at this point in the history
add a parameter to can get all tables (with asserts), use for a bug in migrations, TableMetadataStorage appear as not initialized
  • Loading branch information
eltharin committed Jan 17, 2025
1 parent ec16c82 commit 2445518
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
25 changes: 15 additions & 10 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ protected function doListTableIndexes($table): array
*
* @throws Exception
*/
public function tablesExist($names)
public function tablesExist($names, bool $filterAssetNames = true)
{
if (is_string($names)) {
Deprecation::trigger(
Expand All @@ -322,7 +322,12 @@ public function tablesExist($names)

$names = array_map('strtolower', (array) $names);

return count($names) === count(array_intersect($names, array_map('strtolower', $this->listTableNames())));
return count($names) === count(
array_intersect(
$names,
array_map('strtolower', $this->listTableNames($filterAssetNames)),
),
);
}

/**
Expand All @@ -332,31 +337,31 @@ public function tablesExist($names)
*
* @throws Exception
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)

Check warning on line 340 in src/Schema/AbstractSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractSchemaManager.php#L340

Added line #L340 was not covered by tests
{
$sql = $this->_platform->getListTablesSQL();

$tables = $this->_conn->fetchAllAssociative($sql);
$tableNames = $this->_getPortableTablesList($tables);

return $this->filterAssetNames($tableNames);
return $filterAssetNames ? $this->filterAssetNames($tableNames) : $tableNames;

Check warning on line 347 in src/Schema/AbstractSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractSchemaManager.php#L347

Added line #L347 was not covered by tests
}

/**
* @return list<string>
*
* @throws Exception
*/
protected function doListTableNames(): array
protected function doListTableNames(bool $filterAssetNames = true): array
{
$database = $this->getDatabase(__METHOD__);

return $this->filterAssetNames(
$this->_getPortableTablesList(
$this->selectTableNames($database)
->fetchAllAssociative(),
),
$tableNames = $this->_getPortableTablesList(
$this->selectTableNames($database)
->fetchAllAssociative(),
);

return $filterAssetNames ? $this->filterAssetNames($tableNames) : $tableNames;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritDoc}
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)

Check warning on line 33 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L33

Added line #L33 was not covered by tests
{
return $this->doListTableNames();
return $this->doListTableNames($filterAssetNames);

Check warning on line 35 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L35

Added line #L35 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class MySQLSchemaManager extends AbstractSchemaManager
/**
* {@inheritDoc}
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)

Check warning on line 56 in src/Schema/MySQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/MySQLSchemaManager.php#L56

Added line #L56 was not covered by tests
{
return $this->doListTableNames();
return $this->doListTableNames($filterAssetNames);

Check warning on line 58 in src/Schema/MySQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/MySQLSchemaManager.php#L58

Added line #L58 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritDoc}
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)

Check warning on line 34 in src/Schema/OracleSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/OracleSchemaManager.php#L34

Added line #L34 was not covered by tests
{
return $this->doListTableNames();
return $this->doListTableNames($filterAssetNames);

Check warning on line 36 in src/Schema/OracleSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/OracleSchemaManager.php#L36

Added line #L36 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class PostgreSQLSchemaManager extends AbstractSchemaManager
/**
* {@inheritDoc}
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)

Check warning on line 46 in src/Schema/PostgreSQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/PostgreSQLSchemaManager.php#L46

Added line #L46 was not covered by tests
{
return $this->doListTableNames();
return $this->doListTableNames($filterAssetNames);

Check warning on line 48 in src/Schema/PostgreSQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/PostgreSQLSchemaManager.php#L48

Added line #L48 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritDoc}
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)
{
return $this->doListTableNames();
return $this->doListTableNames($filterAssetNames);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritDoc}
*/
public function listTableNames()
public function listTableNames(bool $filterAssetNames = true)

Check warning on line 47 in src/Schema/SqliteSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/SqliteSchemaManager.php#L47

Added line #L47 was not covered by tests
{
return $this->doListTableNames();
return $this->doListTableNames($filterAssetNames);

Check warning on line 49 in src/Schema/SqliteSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/SqliteSchemaManager.php#L49

Added line #L49 was not covered by tests
}

/**
Expand Down

0 comments on commit 2445518

Please sign in to comment.