<?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 Version20241205202040 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add coupon and order_coupon tables for discount system';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE coupon (id INT AUTO_INCREMENT NOT NULL, partner_id INT DEFAULT NULL, code VARCHAR(50) NOT NULL, discount_percentage INT NOT NULL, valid_from DATETIME NOT NULL, valid_to DATETIME DEFAULT NULL, usage_limit INT DEFAULT NULL, usage_count INT NOT NULL, partner_commission_percentage NUMERIC(5, 2) DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_64BF3F0277153098 (code), INDEX IDX_64BF3F029393F8FE (partner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE order_coupon (id INT AUTO_INCREMENT NOT NULL, order_id INT NOT NULL, coupon_id INT NOT NULL, discount_amount NUMERIC(10, 2) NOT NULL, partner_commission_amount NUMERIC(10, 2) DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_A7302FD78D9F6D38 (order_id), INDEX IDX_A7302FD766C5951B (coupon_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE coupon ADD CONSTRAINT FK_64BF3F029393F8FE FOREIGN KEY (partner_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE order_coupon ADD CONSTRAINT FK_A7302FD78D9F6D38 FOREIGN KEY (order_id) REFERENCES `order` (id)');
$this->addSql('ALTER TABLE order_coupon ADD CONSTRAINT FK_A7302FD766C5951B FOREIGN KEY (coupon_id) REFERENCES coupon (id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE coupon DROP FOREIGN KEY FK_64BF3F029393F8FE');
$this->addSql('ALTER TABLE order_coupon DROP FOREIGN KEY FK_A7302FD78D9F6D38');
$this->addSql('ALTER TABLE order_coupon DROP FOREIGN KEY FK_A7302FD766C5951B');
$this->addSql('DROP TABLE coupon');
$this->addSql('DROP TABLE order_coupon');
}
}