Skip to content

Commit 1dc099f

Browse files
authored
Add primary key to plugin_cmf_deletions table (#252)
* Add primary key to plugin_cmf_deletions * Add migration * Add migration for 6.9 * disable foreign key checks
1 parent 788e8ec commit 1dc099f

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/Installer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function installDatabaseTables()
9191
`entityType` char(20) NOT NULL,
9292
`type` varchar(255) NOT NULL,
9393
`creationDate` bigint(20) unsigned DEFAULT NULL,
94+
PRIMARY KEY (`id`, `entityType`, `type`),
9495
KEY `type` (`entityType`)
9596
) ENGINE=InnoDB DEFAULT CHARSET=utf8'
9697
);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* Pimcore
5+
*
6+
* This source file is available under two different licenses:
7+
* - GNU General Public License version 3 (GPLv3)
8+
* - Pimcore Commercial License (PCL)
9+
* Full copyright and license information is available in
10+
* LICENSE.md which is distributed with this source code.
11+
*
12+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
13+
* @license http://www.pimcore.org/license GPLv3 and PCL
14+
*/
15+
16+
namespace CustomerManagementFrameworkBundle\Migrations\PimcoreX;
17+
18+
use Doctrine\DBAL\Schema\Schema;
19+
use Pimcore\Migrations\BundleAwareMigration;
20+
21+
class Version20220120215900 extends BundleAwareMigration
22+
{
23+
protected function getBundleName(): string
24+
{
25+
return 'PimcoreCustomerManagementFrameworkBundle';
26+
}
27+
28+
/**
29+
* @param Schema $schema
30+
*/
31+
public function up(Schema $schema): void
32+
{
33+
$deletionsTable = $schema->getTable('plugin_cmf_deletions');
34+
35+
if (!$deletionsTable->hasPrimaryKey()) {
36+
$this->addSql('SET foreign_key_checks = 0');
37+
$this->addSql('ALTER TABLE `plugin_cmf_deletions` ADD PRIMARY KEY (`id`, `entityType`, `type`);');
38+
$this->addSql('SET foreign_key_checks = 1');
39+
}
40+
}
41+
42+
/**
43+
* @param Schema $schema
44+
*/
45+
public function down(Schema $schema): void
46+
{
47+
$this->addSql('SET foreign_key_checks = 0');
48+
$this->addSql('ALTER TABLE `plugin_cmf_deletions` DROP INDEX `PRIMARY`;');
49+
$this->addSql('SET foreign_key_checks = 1');
50+
}
51+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* Pimcore
5+
*
6+
* This source file is available under two different licenses:
7+
* - GNU General Public License version 3 (GPLv3)
8+
* - Pimcore Commercial License (PCL)
9+
* Full copyright and license information is available in
10+
* LICENSE.md which is distributed with this source code.
11+
*
12+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
13+
* @license http://www.pimcore.org/license GPLv3 and PCL
14+
*/
15+
16+
namespace CustomerManagementFrameworkBundle\Migrations;
17+
18+
use Doctrine\DBAL\Schema\Schema;
19+
use Pimcore\Migrations\Migration\AbstractPimcoreMigration;
20+
21+
class Version20220120215900 extends AbstractPimcoreMigration
22+
{
23+
/**
24+
* @param Schema $schema
25+
*/
26+
public function up(Schema $schema): void
27+
{
28+
$deletionsTable = $schema->getTable('plugin_cmf_deletions');
29+
30+
if (!$deletionsTable->hasPrimaryKey()) {
31+
$this->addSql('SET foreign_key_checks = 0');
32+
$this->addSql('ALTER TABLE `plugin_cmf_deletions` ADD PRIMARY KEY (`id`, `entityType`, `type`);');
33+
$this->addSql('SET foreign_key_checks = 1');
34+
}
35+
}
36+
37+
/**
38+
* @param Schema $schema
39+
*/
40+
public function down(Schema $schema): void
41+
{
42+
$this->addSql('SET foreign_key_checks = 0');
43+
$this->addSql('ALTER TABLE `plugin_cmf_deletions` DROP INDEX `PRIMARY`;');
44+
$this->addSql('SET foreign_key_checks = 1');
45+
}
46+
}

0 commit comments

Comments
 (0)