Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit a754f32b erstellt von Jan Wennrich's avatar Jan Wennrich
Dateien durchsuchen

refactor: simplifies logic of dropping no longer needed primary keys

Übergeordneter 4768f167
No related branches found
No related tags found
1 Merge Request!8fix: corrects falsy DROP PRIMARY KEY statement in setup
......@@ -225,8 +225,6 @@ public static function onPackageSetup(QUI\Package\Package $Package)
// unique bricks cache patch
$projects = QUI::getProjectManager()->getProjectList();
$databaseName = QUI::getDataBase()->getAttribute('dbname');
foreach ($projects as $Project) {
$projectCacheTable = QUI::getDBProjectTableName(
Manager::TABLE_CACHE,
......@@ -234,18 +232,11 @@ public static function onPackageSetup(QUI\Package\Package $Package)
);
try {
$primaryExists = QUI::getDataBase()->fetchSQL("
SELECT COUNT(constraint_type) AS primary_key_count FROM information_schema.table_constraints
WHERE constraint_type = 'PRIMARY KEY'
AND table_name = '{$projectCacheTable}'
AND TABLE_SCHEMA = '{$databaseName}'
");
$isPrimaryKeyExisting = \boolval($primaryExists[0]['primary_key_count']);
// Primary key should only be dropped if it exists
if ($isPrimaryKeyExisting) {
QUI::getDataBase()->fetchSQL("ALTER TABLE `{$projectCacheTable}` DROP PRIMARY KEY;");
// Only drop composite primary key if it exists
if (QUI::getDataBase()->table()->issetPrimaryKey($projectCacheTable, 'id')
&& QUI::getDataBase()->table()->issetPrimaryKey($projectCacheTable, 'area')) {
// Primary key no longer exists and should be removed
QUI::getDataBase()->getPDO()->exec("ALTER TABLE `{$projectCacheTable}` DROP PRIMARY KEY;");
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::addInfo($Exception->getMessage());
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren