-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reduce NodeTypeField name to maximum 50 characters long.
- Loading branch information
roadiz-ci
committed
Mar 18, 2024
1 parent
29954f4
commit 77a1bef
Showing
24 changed files
with
419 additions
and
272 deletions.
There are no files selected for viewing
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240318184555 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Create new fields to store node-type fields names in nodes_custom_forms, nodes_sources_documents and nodes_to_nodes tables.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
/* | ||
* FIRST CREATE NEW FIELDS | ||
*/ | ||
$this->addSql('ALTER TABLE nodes_custom_forms ADD field_name VARCHAR(250)'); | ||
$this->addSql('ALTER TABLE nodes_sources_documents ADD field_name VARCHAR(250)'); | ||
$this->addSql('ALTER TABLE nodes_to_nodes ADD field_name VARCHAR(250)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->throwIrreversibleMigrationException('Cannot convert node-type fields name back to their identifiers'); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240318184556 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Change node-type fields ID to their names in nodes_custom_forms, nodes_sources_documents and nodes_to_nodes tables.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
/* | ||
* Need to populate new field_name with node-type field names | ||
*/ | ||
$this->connection->beginTransaction(); | ||
$this->connection->executeStatement('UPDATE nodes_custom_forms SET field_name = (SELECT name FROM node_type_fields WHERE id = node_type_field_id)'); | ||
$this->connection->executeStatement('UPDATE nodes_sources_documents SET field_name = (SELECT name FROM node_type_fields WHERE id = node_type_field_id)'); | ||
$this->connection->executeStatement('UPDATE nodes_to_nodes SET field_name = (SELECT name FROM node_type_fields WHERE id = node_type_field_id)'); | ||
$this->connection->commit(); | ||
|
||
$this->addSql('ALTER TABLE nodes_custom_forms DROP FOREIGN KEY FK_4D401A0C47705282'); | ||
$this->addSql('DROP INDEX IDX_4D401A0C47705282 ON nodes_custom_forms'); | ||
$this->addSql('DROP INDEX customform_node_field_position ON nodes_custom_forms'); | ||
$this->addSql('CREATE INDEX customform_node_field_position ON nodes_custom_forms (node_id, field_name, position)'); | ||
$this->addSql('ALTER TABLE nodes_sources_documents DROP FOREIGN KEY FK_1CD104F747705282'); | ||
$this->addSql('DROP INDEX IDX_1CD104F747705282 ON nodes_sources_documents'); | ||
$this->addSql('DROP INDEX nsdoc_field ON nodes_sources_documents'); | ||
$this->addSql('DROP INDEX nsdoc_field_position ON nodes_sources_documents'); | ||
$this->addSql('CREATE INDEX nsdoc_field ON nodes_sources_documents (ns_id, field_name)'); | ||
$this->addSql('CREATE INDEX nsdoc_field_position ON nodes_sources_documents (ns_id, field_name, position)'); | ||
$this->addSql('ALTER TABLE nodes_to_nodes DROP FOREIGN KEY FK_761F9A9147705282'); | ||
$this->addSql('DROP INDEX IDX_761F9A9147705282 ON nodes_to_nodes'); | ||
$this->addSql('DROP INDEX node_a_field ON nodes_to_nodes'); | ||
$this->addSql('DROP INDEX node_a_field_position ON nodes_to_nodes'); | ||
$this->addSql('DROP INDEX node_b_field ON nodes_to_nodes'); | ||
$this->addSql('DROP INDEX node_b_field_position ON nodes_to_nodes'); | ||
$this->addSql('CREATE INDEX node_a_field ON nodes_to_nodes (node_a_id, field_name)'); | ||
$this->addSql('CREATE INDEX node_a_field_position ON nodes_to_nodes (node_a_id, field_name, position)'); | ||
$this->addSql('CREATE INDEX node_b_field ON nodes_to_nodes (node_b_id, field_name)'); | ||
$this->addSql('CREATE INDEX node_b_field_position ON nodes_to_nodes (node_b_id, field_name, position)'); | ||
|
||
/* | ||
* DESTRUCTIVE OPERATIONS | ||
*/ | ||
$this->addSql('ALTER TABLE nodes_custom_forms CHANGE field_name field_name VARCHAR(250) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_sources_documents CHANGE field_name field_name VARCHAR(250) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_to_nodes CHANGE field_name field_name VARCHAR(250) NOT NULL'); | ||
|
||
$this->addSql('ALTER TABLE nodes_custom_forms DROP node_type_field_id'); | ||
$this->addSql('ALTER TABLE nodes_sources_documents DROP node_type_field_id'); | ||
$this->addSql('ALTER TABLE nodes_to_nodes DROP node_type_field_id'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->throwIrreversibleMigrationException('Cannot convert node-type fields name back to their identifiers'); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240318204224 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Rename field_name length to 50 characters maximum.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$result = $this->connection->executeQuery('SELECT max(length(name)) FROM `node_type_fields`'); | ||
$maxLength = $result->fetchOne(); | ||
|
||
$this->skipIf(!is_numeric($maxLength), 'Cannot find node_type_fields name maximum length.'); | ||
$this->skipIf($maxLength >= 50, 'You have at least on node_type_field name that exceed 50 characters long.'); | ||
|
||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE node_type_fields CHANGE name name VARCHAR(50) NOT NULL'); | ||
$this->addSql('CREATE INDEX ntf_name ON node_type_fields (name)'); | ||
$this->addSql('ALTER TABLE nodes_custom_forms CHANGE field_name field_name VARCHAR(50) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_sources_documents CHANGE field_name field_name VARCHAR(50) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_to_nodes CHANGE field_name field_name VARCHAR(50) NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('DROP INDEX ntf_name ON node_type_fields'); | ||
$this->addSql('ALTER TABLE node_type_fields CHANGE name name VARCHAR(250) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_custom_forms CHANGE field_name field_name VARCHAR(250) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_sources_documents CHANGE field_name field_name VARCHAR(250) NOT NULL'); | ||
$this->addSql('ALTER TABLE nodes_to_nodes CHANGE field_name field_name VARCHAR(250) NOT NULL'); | ||
} | ||
} |
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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
trait FieldAwareEntityTrait | ||
{ | ||
#[ORM\Column(name: 'field_name', length: 50, nullable: false)] | ||
#[Assert\Length(max: 50)] | ||
protected string $fieldName; | ||
|
||
public function getFieldName(): string | ||
{ | ||
return $this->fieldName; | ||
} | ||
|
||
public function setFieldName(string $fieldName): self | ||
{ | ||
$this->fieldName = $fieldName; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @deprecated Use setFieldName method instead | ||
*/ | ||
public function setField(NodeTypeFieldInterface $field): self | ||
{ | ||
$this->fieldName = $field->getName(); | ||
return $this; | ||
} | ||
|
||
protected function initializeFieldAwareEntityTrait(?NodeTypeFieldInterface $nodeTypeField = null): void | ||
{ | ||
if (null === $nodeTypeField) { | ||
return; | ||
} | ||
$this->fieldName = $nodeTypeField->getName(); | ||
} | ||
} |
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
Oops, something went wrong.