<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230616064246 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE `crm_bonus_transactions` (id INT AUTO_INCREMENT NOT NULL, bonus_type_id INT DEFAULT NULL, client_id INT NOT NULL, referrer_id INT DEFAULT NULL, type_id INT NOT NULL, contract_id INT DEFAULT NULL, external_code VARCHAR(255) DEFAULT NULL, date DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', bonuses INT DEFAULT 0 NOT NULL, comment VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_C9E011BAE20A50B4 (external_code), INDEX IDX_C9E011BA34D7649B (bonus_type_id), INDEX IDX_C9E011BA19EB6921 (client_id), INDEX IDX_C9E011BA798C22DB (referrer_id), INDEX IDX_C9E011BAC54C8C93 (type_id), INDEX IDX_C9E011BA2576E0FD (contract_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE `list_bonus_transaction_types` (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, sorting INT DEFAULT 500 NOT NULL, code VARCHAR(50) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_CBF46FFB77153098 (code), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE `list_bonus_types` (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, sorting INT DEFAULT 500 NOT NULL, code VARCHAR(50) NOT NULL, client_bonuses INT DEFAULT 0 NOT NULL, referrer_bonuses INT DEFAULT 0 NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_337B91877153098 (code), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE `crm_bonus_transactions` ADD CONSTRAINT FK_C9E011BA34D7649B FOREIGN KEY (bonus_type_id) REFERENCES `list_bonus_transaction_types` (id)');
$this->addSql('ALTER TABLE `crm_bonus_transactions` ADD CONSTRAINT FK_C9E011BA19EB6921 FOREIGN KEY (client_id) REFERENCES `crm_clients` (id)');
$this->addSql('ALTER TABLE `crm_bonus_transactions` ADD CONSTRAINT FK_C9E011BA798C22DB FOREIGN KEY (referrer_id) REFERENCES `crm_clients` (id)');
$this->addSql('ALTER TABLE `crm_bonus_transactions` ADD CONSTRAINT FK_C9E011BAC54C8C93 FOREIGN KEY (type_id) REFERENCES `list_bonus_transaction_types` (id)');
$this->addSql('ALTER TABLE `crm_bonus_transactions` ADD CONSTRAINT FK_C9E011BA2576E0FD FOREIGN KEY (contract_id) REFERENCES `crm_contracts` (id)');
$this->addSql('DROP INDEX uniq_drj7vd2vxory645b ON service_event_log_types');
$this->addSql('CREATE UNIQUE INDEX UNIQ_DDDA2CB477153098 ON service_event_log_types (code)');
$this->addSql('INSERT INTO `list_bonus_types` (`name`, `sorting`, `code`, `client_bonuses`, `referrer_bonuses`, `description`, `created_at`, `updated_at`) VALUES (\'Запроси друзів\', 10, \'invite-friends\', 100, 50, \'Реферальна програма \"Запроси друзів\"\', \''.(new \DateTimeImmutable())->format('Y-m-d H:i:s').'\', \''.(new \DateTimeImmutable())->format('Y-m-d H:i:s').'\')');
$this->addSql('INSERT INTO `list_bonus_transaction_types` (`name`, `sorting`, `code`, `created_at`, `updated_at`) VALUES (\'Отримано\', 10, \'received\', \''.(new \DateTimeImmutable())->format('Y-m-d H:i:s').'\', \''.(new \DateTimeImmutable())->format('Y-m-d H:i:s').'\')');
$this->addSql('INSERT INTO `list_bonus_transaction_types` (`name`, `sorting`, `code`, `created_at`, `updated_at`) VALUES (\'Списано\', 20, \'written-off\', \''.(new \DateTimeImmutable())->format('Y-m-d H:i:s').'\', \''.(new \DateTimeImmutable())->format('Y-m-d H:i:s').'\')');
}
public function down(Schema $schema): void
{
$this->addSql('DELETE FROM `list_bonus_transaction_types` WHERE `code`=\'written-off\'');
$this->addSql('DELETE FROM `list_bonus_transaction_types` WHERE `code`=\'received\'');
$this->addSql('DELETE FROM `list_bonus_types` WHERE `code`=\'invite-friends\'');
$this->addSql('ALTER TABLE `crm_bonus_transactions` DROP FOREIGN KEY FK_C9E011BA34D7649B');
$this->addSql('ALTER TABLE `crm_bonus_transactions` DROP FOREIGN KEY FK_C9E011BA19EB6921');
$this->addSql('ALTER TABLE `crm_bonus_transactions` DROP FOREIGN KEY FK_C9E011BA798C22DB');
$this->addSql('ALTER TABLE `crm_bonus_transactions` DROP FOREIGN KEY FK_C9E011BAC54C8C93');
$this->addSql('ALTER TABLE `crm_bonus_transactions` DROP FOREIGN KEY FK_C9E011BA2576E0FD');
$this->addSql('DROP TABLE `crm_bonus_transactions`');
$this->addSql('DROP TABLE `list_bonus_transaction_types`');
$this->addSql('DROP TABLE `list_bonus_types`');
$this->addSql('DROP INDEX uniq_ddda2cb477153098 ON `service_event_log_types`');
$this->addSql('CREATE UNIQUE INDEX UNIQ_DRJ7VD2VXORY645B ON `service_event_log_types` (code)');
}
}