mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 10:18:56 +02:00
Allow database migration from legacy versions even if the perms_label column is missing in the groups table
This fixes issue #366 and #67
This commit is contained in:
parent
55943f5d8f
commit
4bed50d894
2 changed files with 24 additions and 0 deletions
|
@ -132,6 +132,24 @@ abstract class AbstractMultiPlatformMigration extends AbstractMigration
|
|||
return $result > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a column exists in a table.
|
||||
* @return bool Returns true, if the column exists
|
||||
* @throws Exception
|
||||
*/
|
||||
public function doesColumnExist(string $table, string $column_name): bool
|
||||
{
|
||||
$db_type = $this->getDatabaseType();
|
||||
if ($db_type !== 'mysql') {
|
||||
throw new \RuntimeException('This method is only supported for MySQL/MariaDB databases!');
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column_name'";
|
||||
$result = (int) $this->connection->fetchOne($sql);
|
||||
|
||||
return $result > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database type of the used database.
|
||||
* @return string|null Returns 'mysql' for MySQL/MariaDB and 'sqlite' for SQLite. Returns null if unknown type
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue