-
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.
BREAKING CHANGE: Make sure you don't have fields with name longer than 50 characters before migrating. Migration can be skipped if so.
- Loading branch information
1 parent
fb5a2d8
commit 8d7529a
Showing
3 changed files
with
49 additions
and
4 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,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