<?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 Version20240320161514 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('ALTER TABLE user_subscriptions ADD subscription_state VARCHAR(255) DEFAULT NULL, ADD acknowledgement_state VARCHAR(255) DEFAULT NULL, ADD latest_order_id VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE users ADD latest_subscription_id INT UNSIGNED DEFAULT NULL, DROP start_subscription, DROP end_subscription, DROP active_subscription');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E918EA7247 FOREIGN KEY (latest_subscription_id) REFERENCES user_subscriptions (id) ON DELETE SET NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E918EA7247 ON users (latest_subscription_id)');
$this->addSql("UPDATE users u SET latest_subscription_id = (
SELECT us.id FROM user_subscriptions us WHERE us.user_id = u.id
ORDER BY us.id DESC LIMIT 1
)");
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users DROP FOREIGN KEY FK_1483A5E918EA7247');
$this->addSql('DROP INDEX UNIQ_1483A5E918EA7247 ON users');
$this->addSql('ALTER TABLE users DROP latest_subscription_id, ADD start_subscription DATE DEFAULT NULL, ADD end_subscription DATE DEFAULT NULL, ADD active_subscription TINYINT(1) DEFAULT 0 NOT NULL');
$this->addSql('ALTER TABLE user_subscriptions DROP subscription_state, DROP acknowledgement_state, DROP latest_order_id');
}
}