<?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 Version20180817221423 extends AbstractMigration
{
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('RENAME TABLE customers_complaints TO customer_complaint');
$this->addSql('ALTER TABLE customer_complaint ENGINE = InnoDB');
$this->addSql('ALTER TABLE customer_complaint CHARACTER SET = utf8mb4');
$this->addSql('UPDATE customer_complaint SET status = 0 WHERE status IS NULL');
$this->addSql('
ALTER TABLE customer_complaint
CHANGE customers_id customer_id INT DEFAULT NULL,
CHANGE administrators_id user_id INT DEFAULT NULL,
CHANGE customers_complaints_outcomes_id outcome_id INT DEFAULT NULL,
CHANGE customers_complaints_types_id type_id INT DEFAULT NULL,
CHANGE complaint message LONGTEXT DEFAULT NULL,
CHANGE status enabled TINYINT(1) NOT NULL,
CHANGE date_added created_at DATETIME NOT NULL,
CHANGE last_modified modified_at DATETIME NOT NULL
');
$this->addSql('DROP INDEX idx_customers_id ON customer_complaint');
$this->addSql('DROP INDEX idx_administrators_id ON customer_complaint');
$this->addSql('CREATE INDEX IDX_F4DACAAF9395C3F3 ON customer_complaint (customer_id)');
$this->addSql('CREATE INDEX IDX_F4DACAAFA76ED395 ON customer_complaint (user_id)');
$this->addSql('CREATE INDEX IDX_F4DACAAFE6EE6D63 ON customer_complaint (outcome_id)');
$this->addSql('CREATE INDEX IDX_F4DACAAFC54C8C93 ON customer_complaint (type_id)');
$this->addSql('RENAME TABLE customers_files TO customer_file');
$this->addSql('ALTER TABLE customer_file ENGINE = InnoDB');
$this->addSql('ALTER TABLE customer_file CHARACTER SET = utf8mb4');
$this->addSql('UPDATE customer_file SET is_public = 0 WHERE is_public IS NULL');
$this->addSql('ALTER TABLE customer_file ADD modified_at DATETIME DEFAULT NULL');
$this->addSql('UPDATE customer_file SET modified_at = date_added');
$this->addSql('
ALTER TABLE customer_file
CHANGE customers_id customer_id INT DEFAULT NULL,
CHANGE administrators_id user_id INT DEFAULT NULL,
CHANGE folders_id folder_id INT DEFAULT NULL,
CHANGE title name VARCHAR(255) NOT NULL,
CHANGE file file VARCHAR(255) NOT NULL,
CHANGE is_public public TINYINT(1) NOT NULL,
CHANGE date_added created_at DATETIME NOT NULL,
CHANGE modified_at modified_at DATETIME NOT NULL
');
$this->addSql('DROP INDEX idx_customers_id ON customer_file');
$this->addSql('CREATE INDEX IDX_D80E92679395C3F3 ON customer_file (customer_id)');
$this->addSql('CREATE INDEX IDX_D80E9267A76ED395 ON customer_file (user_id)');
$this->addSql('CREATE INDEX IDX_D80E9267162CB942 ON customer_file (folder_id)');
$this->addSql('UPDATE customers_services SET price = price * quantity');
$this->addSql('RENAME TABLE customers_services TO customer_invoice');
$this->addSql('ALTER TABLE customer_invoice ENGINE = InnoDB');
$this->addSql('ALTER TABLE customer_invoice CHARACTER SET = utf8mb4');
$this->addSql('UPDATE customer_invoice SET is_first = 0 WHERE is_first IS NULL');
$this->addSql('UPDATE customer_invoice SET products_id = 1 WHERE products_id IS NULL OR products_id = 0');
$this->addSql('
ALTER TABLE customer_invoice
DROP quantity,
CHANGE customers_id customer_id INT DEFAULT NULL,
CHANGE administrators_id user_id INT DEFAULT NULL,
CHANGE products_id product_id INT DEFAULT NULL,
CHANGE description description VARCHAR(255) DEFAULT NULL,
CHANGE price price NUMERIC(10, 2) DEFAULT NULL,
CHANGE is_first first TINYINT(1) NOT NULL,
CHANGE date_added created_at DATETIME NOT NULL,
CHANGE last_modified modified_at DATETIME NOT NULL
');
$this->addSql('DROP INDEX idx_customers_id ON customer_invoice');
$this->addSql('DROP INDEX idx_administrators_id ON customer_invoice');
$this->addSql('DROP INDEX idx_customers_id_products_id ON customer_invoice');
$this->addSql('CREATE INDEX IDX_8CB8B3FA9395C3F3 ON customer_invoice (customer_id)');
$this->addSql('CREATE INDEX IDX_8CB8B3FAA76ED395 ON customer_invoice (user_id)');
$this->addSql('CREATE INDEX IDX_8CB8B3FA4584665A ON customer_invoice (product_id)');
$this->addSql('DELETE FROM customer_complaint WHERE customer_id NOT IN (SELECT id FROM customer)');
$this->addSql('UPDATE customer_complaint SET user_id = NULL WHERE user_id NOT IN (SELECT id FROM user)');
$this->addSql('UPDATE customer_complaint SET outcome_id = NULL WHERE outcome_id NOT IN (SELECT id FROM config_complaint_outcome)');
$this->addSql('UPDATE customer_complaint SET type_id = NULL WHERE type_id NOT IN (SELECT id FROM config_complaint_type)');
$this->addSql('DELETE FROM customer_file WHERE customer_id NOT IN (SELECT id FROM customer)');
$this->addSql('UPDATE customer_file SET user_id = NULL WHERE user_id NOT IN (SELECT id FROM user)');
$this->addSql('UPDATE customer_file SET folder_id = NULL WHERE folder_id NOT IN (SELECT id FROM config_folder)');
$this->addSql('DELETE FROM customer_invoice WHERE customer_id NOT IN (SELECT id FROM customer)');
$this->addSql('UPDATE customer_invoice SET user_id = NULL WHERE user_id NOT IN (SELECT id FROM user)');
$this->addSql('UPDATE customer_invoice SET product_id = NULL WHERE product_id NOT IN (SELECT id FROM config_product)');
$this->addSql('ALTER TABLE customer_complaint ADD CONSTRAINT FK_F4DACAAF9395C3F3 FOREIGN KEY (customer_id) REFERENCES customer (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE customer_complaint ADD CONSTRAINT FK_F4DACAAFA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_complaint ADD CONSTRAINT FK_F4DACAAFE6EE6D63 FOREIGN KEY (outcome_id) REFERENCES config_complaint_outcome (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_complaint ADD CONSTRAINT FK_F4DACAAFC54C8C93 FOREIGN KEY (type_id) REFERENCES config_complaint_type (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_file ADD CONSTRAINT FK_D80E92679395C3F3 FOREIGN KEY (customer_id) REFERENCES customer (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE customer_file ADD CONSTRAINT FK_D80E9267A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_file ADD CONSTRAINT FK_D80E9267162CB942 FOREIGN KEY (folder_id) REFERENCES config_folder (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_invoice ADD CONSTRAINT FK_8CB8B3FA9395C3F3 FOREIGN KEY (customer_id) REFERENCES customer (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE customer_invoice ADD CONSTRAINT FK_8CB8B3FAA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE customer_invoice ADD CONSTRAINT FK_8CB8B3FA4584665A FOREIGN KEY (product_id) REFERENCES config_product (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE customer_invoice DROP FOREIGN KEY FK_8CB8B3FA4584665A');
$this->addSql('ALTER TABLE customer_invoice DROP FOREIGN KEY FK_8CB8B3FAA76ED395');
$this->addSql('ALTER TABLE customer_invoice DROP FOREIGN KEY FK_8CB8B3FA9395C3F3');
$this->addSql('ALTER TABLE customer_file DROP FOREIGN KEY FK_D80E9267162CB942');
$this->addSql('ALTER TABLE customer_file DROP FOREIGN KEY FK_D80E9267A76ED395');
$this->addSql('ALTER TABLE customer_file DROP FOREIGN KEY FK_D80E92679395C3F3');
$this->addSql('ALTER TABLE customer_complaint DROP FOREIGN KEY FK_F4DACAAFC54C8C93');
$this->addSql('ALTER TABLE customer_complaint DROP FOREIGN KEY FK_F4DACAAFE6EE6D63');
$this->addSql('ALTER TABLE customer_complaint DROP FOREIGN KEY FK_F4DACAAFA76ED395');
$this->addSql('ALTER TABLE customer_complaint DROP FOREIGN KEY FK_F4DACAAF9395C3F3');
$this->addSql('RENAME TABLE customer_complaint TO customers_complaints');
$this->addSql('ALTER TABLE customers_complaints ENGINE = MyISAM');
$this->addSql('ALTER TABLE customers_complaints CHARACTER SET = latin1');
$this->addSql('
ALTER TABLE customers_complaints
CHANGE customer_id customers_id INT NOT NULL,
CHANGE user_id administrators_id INT NOT NULL,
CHANGE outcome_id customers_complaints_outcomes_id INT NOT NULL,
CHANGE type_id customers_complaints_types_id INT NOT NULL,
CHANGE message complaint TEXT DEFAULT NULL,
CHANGE enabled status TINYINT(1) DEFAULT \'0\',
CHANGE created_at date_added DATETIME DEFAULT NULL,
CHANGE modified_at last_modified DATETIME DEFAULT NULL
');
$this->addSql('DROP INDEX IDX_F4DACAAF9395C3F3 ON customers_complaints');
$this->addSql('DROP INDEX IDX_F4DACAAFA76ED395 ON customers_complaints');
$this->addSql('DROP INDEX IDX_F4DACAAFE6EE6D63 ON customers_complaints');
$this->addSql('DROP INDEX IDX_F4DACAAFC54C8C93 ON customers_complaints');
$this->addSql('CREATE INDEX idx_administrators_id ON customers_complaints (administrators_id)');
$this->addSql('CREATE INDEX idx_customers_id ON customers_complaints (customers_id)');
$this->addSql('RENAME TABLE customer_file TO customers_files');
$this->addSql('ALTER TABLE customers_files ENGINE = MyISAM');
$this->addSql('ALTER TABLE customers_files CHARACTER SET = latin1');
$this->addSql('
ALTER TABLE customers_files
DROP modified_at,
CHANGE customer_id customers_id INT NOT NULL,
CHANGE user_id administrators_id INT NOT NULL,
CHANGE folder_id folders_id INT DEFAULT NULL,
CHANGE name title VARCHAR(255) NOT NULL,
CHANGE file file VARCHAR(255) DEFAULT NULL,
CHANGE public is_public TINYINT(1) DEFAULT \'1\',
CHANGE created_at date_added DATETIME DEFAULT NULL
');
$this->addSql('DROP INDEX IDX_D80E92679395C3F3 ON customers_files');
$this->addSql('DROP INDEX IDX_D80E9267A76ED395 ON customers_files');
$this->addSql('DROP INDEX IDX_D80E9267162CB942 ON customers_files');
$this->addSql('CREATE INDEX idx_customers_id ON customers_files (customers_id)');
$this->addSql('RENAME TABLE customer_invoice TO customers_services');
$this->addSql('ALTER TABLE customers_services ENGINE = MyISAM');
$this->addSql('ALTER TABLE customers_services CHARACTER SET = latin1');
$this->addSql('
ALTER TABLE customers_services
ADD quantity SMALLINT(6) NOT NULL AFTER description,
CHANGE customer_id customers_id INT NOT NULL,
CHANGE user_id administrators_id INT NOT NULL,
CHANGE product_id products_id INT NOT NULL,
CHANGE description description VARCHAR(255) DEFAULT NULL,
CHANGE price price NUMERIC(15, 2) DEFAULT \'0.00\',
CHANGE first is_first TINYINT(1) DEFAULT \'0\',
CHANGE created_at date_added DATETIME DEFAULT NULL,
CHANGE modified_at last_modified DATETIME DEFAULT NULL
');
$this->addSql('UPDATE customers_services SET quantity = 1');
$this->addSql('DROP INDEX IDX_8CB8B3FA9395C3F3 ON customers_services');
$this->addSql('DROP INDEX IDX_8CB8B3FAA76ED395 ON customers_services');
$this->addSql('DROP INDEX IDX_8CB8B3FA4584665A ON customers_services');
$this->addSql('CREATE INDEX idx_administrators_id ON customers_services (administrators_id)');
$this->addSql('CREATE INDEX idx_customers_id ON customers_services (customers_id)');
$this->addSql('CREATE INDEX idx_customers_id_products_id ON customers_services (customers_id, products_id)');
}
}