<?php

declare(strict_types=1);

namespace App\Infrastructure\Migration\Doctrine;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20221031050936 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Adds the table "projection" that holds the current state of all projections.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE projection (id BIGSERIAL NOT NULL, position BIGINT NOT NULL, projection_name VARCHAR(255) NOT NULL, aggregate_name VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, last_update_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE UNIQUE INDEX uniq_projection_projection_name_aggregate_name ON projection (projection_name, aggregate_name)');
        $this->addSql('COMMENT ON COLUMN projection.created_at IS \'(DC2Type:datetime_immutable)\'');
        $this->addSql('COMMENT ON COLUMN projection.last_update_at IS \'(DC2Type:datetime_immutable)\'');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE projection');
    }
}
