<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20221108095046 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adds upload table.';
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->hasTable('upload'),
'The upload table was already created!'
);
$table = $schema->createTable('upload');
$table->addColumn('id', Types::GUID)->setNotnull(true);
$table->addColumn('user_id', Types::GUID)->setNotnull(true);
$table->addColumn('uploaded_at', Types::DATE_IMMUTABLE)->setNotnull(true);
$table->addColumn('filename', Types::STRING, ['length' => 255])->setNotnull(true);
$table->addColumn('extension', Types::STRING, ['length' => 4])->setNotnull(true);
$table->addColumn('file_type', Types::STRING, ['length' => 15])->setNotnull(true);
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint('mycmcm_user', ['user_id'], ['id'], [], 'fk_mycmcm_user_upload');
$table->addIndex(['user_id'], 'idx_upload_user_id');
}
public function down(Schema $schema): void
{
$this->skipIf(
false === $schema->hasTable('upload'),
'The upload table was already removed!'
);
$schema->dropTable('upload');
}
}