-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Framework] Fix parameters groups migrations (#3557)
Co-authored-by: Michal Vanek <[email protected]> Co-authored-by: Martin Grossmann <[email protected]>
- Loading branch information
1 parent
644a4d0
commit a3cec58
Showing
5 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration; | ||
|
||
class Version20241101073720 extends AbstractMigration | ||
{ | ||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
if ($this->isAppMigrationNotInstalledRemoveIfExists('Version20200220124729')) { | ||
$this->sql(' | ||
CREATE TABLE parameter_groups ( | ||
id SERIAL NOT NULL, | ||
akeneo_code VARCHAR(100) NOT NULL, | ||
PRIMARY KEY(id) | ||
)'); | ||
$this->sql('CREATE UNIQUE INDEX UNIQ_14133381CC7118A2 ON parameter_groups (akeneo_code)'); | ||
$this->sql('ALTER TABLE parameters ADD group_id INT DEFAULT NULL'); | ||
$this->sql('ALTER TABLE parameters ADD akeneo_code VARCHAR(100) DEFAULT NULL'); | ||
$this->sql('ALTER TABLE parameters ADD akeneo_type VARCHAR(100) DEFAULT NULL'); | ||
|
||
$this->sql(' | ||
ALTER TABLE | ||
parameters | ||
ADD | ||
CONSTRAINT FK_69348FEFE54D947 FOREIGN KEY (group_id) REFERENCES parameter_groups (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->sql('CREATE UNIQUE INDEX UNIQ_69348FECC7118A2 ON parameters (akeneo_code)'); | ||
$this->sql('CREATE INDEX IDX_69348FEFE54D947 ON parameters (group_id)'); | ||
|
||
$this->sql(' | ||
CREATE TABLE parameter_groups_translations ( | ||
id SERIAL NOT NULL, | ||
translatable_id INT NOT NULL, | ||
name VARCHAR(100) NOT NULL, | ||
locale VARCHAR(255) NOT NULL, | ||
PRIMARY KEY(id) | ||
)'); | ||
$this->sql('CREATE INDEX IDX_9BF623102C2AC5D3 ON parameter_groups_translations (translatable_id)'); | ||
$this->sql(' | ||
CREATE UNIQUE INDEX parameter_groups_translations_uniq_trans ON parameter_groups_translations (translatable_id, locale)'); | ||
$this->sql(' | ||
ALTER TABLE | ||
parameter_groups_translations | ||
ADD | ||
CONSTRAINT FK_9BF623102C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES parameter_groups (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->sql('ALTER TABLE parameter_groups ADD ordering_priority INT NOT NULL'); | ||
} | ||
|
||
$this->sql('ALTER TABLE parameter_groups DROP COLUMN IF EXISTS akeneo_code'); | ||
$this->sql('ALTER TABLE parameters DROP COLUMN IF EXISTS akeneo_code'); | ||
$this->sql('ALTER TABLE parameters DROP COLUMN IF EXISTS akeneo_type'); | ||
} | ||
|
||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241101083720 extends AbstractMigration | ||
{ | ||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->sql('ALTER TABLE parameter_groups ADD position INT NOT NULL DEFAULT 0'); | ||
$this->sql('WITH ordered_groups AS ( | ||
SELECT id, | ||
ROW_NUMBER() OVER (ORDER BY ordering_priority DESC, id ASC) - 1 AS new_position | ||
FROM parameter_groups | ||
) | ||
UPDATE parameter_groups | ||
SET position = ordered_groups.new_position | ||
FROM ordered_groups | ||
WHERE parameter_groups.id = ordered_groups.id'); | ||
$this->sql('ALTER TABLE parameter_groups ALTER position DROP DEFAULT'); | ||
$this->sql('ALTER TABLE parameter_groups DROP ordering_priority'); | ||
} | ||
|
||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters