41 lines
2.2 KiB
PHP
41 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
final class Version20251028072231 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add RegistrationToken';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('CREATE TEMPORARY TABLE __temp__registration_token AS SELECT id, user_id FROM registration_token');
|
|
$this->addSql('DROP TABLE registration_token');
|
|
$this->addSql('CREATE TABLE registration_token (id BLOB NOT NULL --(DC2Type:uuid)
|
|
, user_id INTEGER DEFAULT NULL, created_by_id INTEGER NOT NULL, created_at DATETIME NOT NULL --(DC2Type:datetime_immutable)
|
|
, PRIMARY KEY(id), CONSTRAINT FK_D09D01D3A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D09D01D3B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
|
$this->addSql('INSERT INTO registration_token (id, user_id) SELECT id, user_id FROM __temp__registration_token');
|
|
$this->addSql('DROP TABLE __temp__registration_token');
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_D09D01D3A76ED395 ON registration_token (user_id)');
|
|
$this->addSql('CREATE INDEX IDX_D09D01D3B03A8386 ON registration_token (created_by_id)');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('CREATE TEMPORARY TABLE __temp__registration_token AS SELECT id, user_id FROM registration_token');
|
|
$this->addSql('DROP TABLE registration_token');
|
|
$this->addSql('CREATE TABLE registration_token (id BLOB NOT NULL --(DC2Type:uuid)
|
|
, user_id INTEGER DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_D09D01D3A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
|
$this->addSql('INSERT INTO registration_token (id, user_id) SELECT id, user_id FROM __temp__registration_token');
|
|
$this->addSql('DROP TABLE __temp__registration_token');
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_D09D01D3A76ED395 ON registration_token (user_id)');
|
|
}
|
|
}
|