<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220623122203 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE static_field_formats (id INT AUTO_INCREMENT NOT NULL, static_field_id INT DEFAULT NULL, name VARCHAR(50) DEFAULT NULL, INDEX fk__static_field (static_field_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE static_field_formats ADD CONSTRAINT FK_CB37BC105AAF778C FOREIGN KEY (static_field_id) REFERENCES static_fields (id)');
$this->addSql('ALTER TABLE endpoind_fields CHANGE name name VARCHAR(250) DEFAULT NULL, CHANGE example_value example_value VARCHAR(250) DEFAULT NULL');
$this->addSql('ALTER TABLE model_fields CHANGE name name VARCHAR(250) DEFAULT NULL');
$this->addSql('ALTER TABLE static_fields ADD swagger_name VARCHAR(50) DEFAULT NULL');
$staticFieldsAll = array('integer', 'boolean', 'string', 'nested', 'object', 'keyword', 'date', 'time');
$staticFieldNames = array('keyword', 'date', 'time');
$staticFieldSwaggerNames = array('integer', 'boolean', 'string', 'array', 'object', 'string', 'date', 'string');
foreach($staticFieldNames as $key => $staticFieldName) {
$this->addSql('INSERT INTO static_fields (name) VALUES (?)', array($staticFieldName));
}
$i = 1;
foreach ($staticFieldsAll as $key => $value){
$this->addSql('UPDATE static_fields SET swagger_name = "' .$staticFieldSwaggerNames[$key] . '" WHERE id = "'. $i . '"');
$i++;
}
$staticFieldDateFormats = array('Y-m-d', 'Y/m/d', 'd-m-Y', 'd/m/Y');
foreach ($staticFieldDateFormats as $staticFieldDateFormat){
$this->addSql('INSERT INTO static_field_formats (name, static_field_id) VALUES (?, ?)', array($staticFieldDateFormat, 7));
}
$staticFieldTimeFormats = array('h:i:sa', 'h.i.sa');
foreach ($staticFieldTimeFormats as $staticFieldTimeFormat){
$this->addSql('INSERT INTO static_field_formats (name, static_field_id) VALUES (?, ?)', array($staticFieldTimeFormat,8));
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE static_field_formats');
$this->addSql('ALTER TABLE endpoind_fields CHANGE name name VARCHAR(50) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE example_value example_value VARCHAR(50) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
$this->addSql('ALTER TABLE model_fields CHANGE name name VARCHAR(50) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
$this->addSql('ALTER TABLE static_fields DROP swagger_name');
}
}