<?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 Version20221123072219 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$qb = $this->connection
->createQueryBuilder()
->select('u.id')
->from('public.user', 'u')
->setMaxResults(1);
$userId = $qb->executeQuery()->fetchOne();
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE "user" ADD created_by_id INT NOT NULL DEFAULT ' . $userId);
$this->addSql('ALTER TABLE "user" ADD created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL');
$this->addSql('ALTER TABLE "user" ADD file_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE "user" ADD first_name VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE "user" ADD second_name VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE "user" ADD last_name VARCHAR(255) DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN "user".first_name IS \'Имя\'');
$this->addSql('COMMENT ON COLUMN "user".second_name IS \'Отчество\'');
$this->addSql('COMMENT ON COLUMN "user".last_name IS \'Фамилия\'');
$this->addSql('ALTER TABLE "user" ADD CONSTRAINT FK_8D93D64993CB796C FOREIGN KEY (file_id) REFERENCES file (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE "user" ADD CONSTRAINT FK_8D93D649B03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_8D93D64993CB796C ON "user" (file_id)');
$this->addSql('CREATE INDEX IDX_8D93D649B03A8386 ON "user" (created_by_id)');
$this->addSql('ALTER TABLE "user" ALTER COLUMN created_by_id DROP DEFAULT');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE "user" DROP CONSTRAINT FK_8D93D64993CB796C');
$this->addSql('ALTER TABLE "user" DROP CONSTRAINT FK_8D93D649B03A8386');
$this->addSql('DROP INDEX IDX_8D93D64993CB796C');
$this->addSql('DROP INDEX IDX_8D93D649B03A8386');
$this->addSql('ALTER TABLE "user" DROP file_id');
$this->addSql('ALTER TABLE "user" DROP created_by_id');
$this->addSql('ALTER TABLE "user" DROP first_name');
$this->addSql('ALTER TABLE "user" DROP second_name');
$this->addSql('ALTER TABLE "user" DROP last_name');
$this->addSql('ALTER TABLE "user" DROP created_at');
}
}