<?php
declare(strict_types=1);
namespace SuppliersBundleMigrations;
use DateTime;
use Doctrine\DBAL\Schema\Schema;
use App\Services\ObjectSerialize;
use Symfony\Component\Uid\UuidV6;
use Doctrine\Migrations\AbstractMigration;
final class Version20221206151510 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE suppliers_bundle__product_supplier (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', product_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', declination_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', supplier_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', reference VARCHAR(128) DEFAULT NULL, wholesale_price NUMERIC(20, 6) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_default TINYINT(1) NOT NULL, INDEX IDX_FCE3DD2F4584665A (product_id), INDEX IDX_FCE3DD2F9941A932 (declination_id), INDEX IDX_FCE3DD2F2ADD6D8C (supplier_id), INDEX IDX_FCE3DD2FB03A8386 (created_by_id), INDEX IDX_FCE3DD2F896DBBDE (updated_by_id), INDEX IDX_FCE3DD2FC76F1F52 (deleted_by_id), INDEX reference (reference), INDEX wholesale_price (wholesale_price), INDEX is_default (is_default), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE suppliers_bundle__supplier (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', country_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', country_state_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', supplier_type_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(128) NOT NULL, city VARCHAR(128) DEFAULT NULL, postcode VARCHAR(32) DEFAULT NULL, contact_name VARCHAR(255) DEFAULT NULL, address VARCHAR(255) DEFAULT NULL, address2 VARCHAR(255) DEFAULT NULL, vat_number VARCHAR(32) DEFAULT NULL, phone VARCHAR(32) DEFAULT NULL, mobile_phone VARCHAR(32) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, note LONGTEXT DEFAULT NULL, free_of_charge NUMERIC(20, 6) DEFAULT NULL, ape VARCHAR(8) DEFAULT NULL, siret VARCHAR(25) DEFAULT NULL, rib VARCHAR(50) DEFAULT NULL, iban VARCHAR(34) DEFAULT NULL, bic VARCHAR(11) DEFAULT NULL, payment_method VARCHAR(255) DEFAULT NULL, bank_name VARCHAR(255) DEFAULT NULL, activity VARCHAR(255) DEFAULT NULL, reference VARCHAR(128) DEFAULT NULL, accounting_account VARCHAR(128) DEFAULT NULL, customer_number VARCHAR(128) DEFAULT NULL, minimum_order NUMERIC(20, 6) DEFAULT NULL, exemption TINYINT(1) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, INDEX IDX_DC54A5DAF92F3E70 (country_id), INDEX IDX_DC54A5DA36126D7C (country_state_id), INDEX IDX_DC54A5DA4429F88C (supplier_type_id), INDEX IDX_DC54A5DAB03A8386 (created_by_id), INDEX IDX_DC54A5DA896DBBDE (updated_by_id), INDEX IDX_DC54A5DAC76F1F52 (deleted_by_id), INDEX name (name), INDEX reference (reference), INDEX activity (activity), INDEX city (city), INDEX is_active (is_active), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE suppliers_bundle__supplier_address (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', supplier_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', country_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', country_state_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', alias VARCHAR(255) DEFAULT NULL, address VARCHAR(255) DEFAULT NULL, address2 VARCHAR(255) DEFAULT NULL, city VARCHAR(128) DEFAULT NULL, postcode VARCHAR(32) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_2052C0582ADD6D8C (supplier_id), INDEX IDX_2052C058F92F3E70 (country_id), INDEX IDX_2052C05836126D7C (country_state_id), INDEX IDX_2052C058B03A8386 (created_by_id), INDEX IDX_2052C058896DBBDE (updated_by_id), INDEX IDX_2052C058C76F1F52 (deleted_by_id), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE suppliers_bundle__supplier_contact (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', supplier_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', firstname VARCHAR(128) DEFAULT NULL, lastname VARCHAR(128) DEFAULT NULL, phone VARCHAR(32) DEFAULT NULL, mobile_phone VARCHAR(32) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, fax VARCHAR(255) DEFAULT NULL, work_post VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_617E49E12ADD6D8C (supplier_id), INDEX IDX_617E49E1B03A8386 (created_by_id), INDEX IDX_617E49E1896DBBDE (updated_by_id), INDEX IDX_617E49E1C76F1F52 (deleted_by_id), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE suppliers_bundle__supplier_context (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', supplier_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', INDEX IDX_CF412AA72ADD6D8C (supplier_id), INDEX IDX_CF412AA76B00C1CF (context_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE suppliers_bundle__supplier_type (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(128) NOT NULL, number INT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, INDEX IDX_2E33A582B03A8386 (created_by_id), INDEX IDX_2E33A582896DBBDE (updated_by_id), INDEX IDX_2E33A582C76F1F52 (deleted_by_id), INDEX name (name), INDEX is_active (is_active), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE suppliers_bundle__supplier_type_translations (id INT AUTO_INCREMENT NOT NULL, object_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', locale VARCHAR(8) NOT NULL, field VARCHAR(32) NOT NULL, content LONGTEXT DEFAULT NULL, INDEX IDX_5C93F504232D562B (object_id), FULLTEXT INDEX content (content), UNIQUE INDEX lookup_unique_idx (locale, object_id, field), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier ADD CONSTRAINT FK_FCE3DD2F4584665A FOREIGN KEY (product_id) REFERENCES products_bundle__product (id)');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier ADD CONSTRAINT FK_FCE3DD2F9941A932 FOREIGN KEY (declination_id) REFERENCES products_bundle__declination (id)');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier ADD CONSTRAINT FK_FCE3DD2F2ADD6D8C FOREIGN KEY (supplier_id) REFERENCES suppliers_bundle__supplier (id)');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier ADD CONSTRAINT FK_FCE3DD2FB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier ADD CONSTRAINT FK_FCE3DD2F896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier ADD CONSTRAINT FK_FCE3DD2FC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier ADD CONSTRAINT FK_DC54A5DAF92F3E70 FOREIGN KEY (country_id) REFERENCES country (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier ADD CONSTRAINT FK_DC54A5DA36126D7C FOREIGN KEY (country_state_id) REFERENCES country_state (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier ADD CONSTRAINT FK_DC54A5DA4429F88C FOREIGN KEY (supplier_type_id) REFERENCES suppliers_bundle__supplier_type (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier ADD CONSTRAINT FK_DC54A5DAB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier ADD CONSTRAINT FK_DC54A5DA896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier ADD CONSTRAINT FK_DC54A5DAC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address ADD CONSTRAINT FK_2052C0582ADD6D8C FOREIGN KEY (supplier_id) REFERENCES suppliers_bundle__supplier (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address ADD CONSTRAINT FK_2052C058F92F3E70 FOREIGN KEY (country_id) REFERENCES country (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address ADD CONSTRAINT FK_2052C05836126D7C FOREIGN KEY (country_state_id) REFERENCES country_state (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address ADD CONSTRAINT FK_2052C058B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address ADD CONSTRAINT FK_2052C058896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address ADD CONSTRAINT FK_2052C058C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact ADD CONSTRAINT FK_617E49E12ADD6D8C FOREIGN KEY (supplier_id) REFERENCES suppliers_bundle__supplier (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact ADD CONSTRAINT FK_617E49E1B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact ADD CONSTRAINT FK_617E49E1896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact ADD CONSTRAINT FK_617E49E1C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_context ADD CONSTRAINT FK_CF412AA72ADD6D8C FOREIGN KEY (supplier_id) REFERENCES suppliers_bundle__supplier (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_context ADD CONSTRAINT FK_CF412AA76B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type ADD CONSTRAINT FK_2E33A582B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type ADD CONSTRAINT FK_2E33A582896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type ADD CONSTRAINT FK_2E33A582C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type_translations ADD CONSTRAINT FK_5C93F504232D562B FOREIGN KEY (object_id) REFERENCES suppliers_bundle__supplier_type (id) ON DELETE CASCADE');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'suppliers_bundle__shared_suppliers',
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => '0']),
'created_at' => (new DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new DateTime())->format('Y-m-d H:i:s')
]);
$languages = $this->connection->executeQuery('SELECT * FROM language WHERE deleted_at IS NULL')
->fetchAllAssociative();
$rootLocale = 'en';
$defaultLocale = $this->connection
->executeQuery('SELECT locale FROM language WHERE deleted_at IS NULL AND is_default = 1')
->fetchOne() ?: 'en';
$supplierTypes = [
['names' => ['fr' => 'Grossiste', 'en' => 'Wholesaler'], 'number' => 1],
['names' => ['fr' => 'Sous-traitant', 'en' => 'Subcontractor'], 'number' => 2],
['names' => ['fr' => 'Fabricant', 'en' => 'Manufacturer'], 'number' => 3]
];
foreach ($supplierTypes as $supplierType) {
$supplierTypeId = (new UuidV6())->toBinary();
$this->connection->insert('suppliers_bundle__supplier_type', [
'id' => $supplierTypeId,
'name' => !empty($supplierType['names'][$defaultLocale]) ?
$supplierType['names'][$defaultLocale] : $supplierType['names'][$rootLocale],
'number' => $supplierType['number'],
'is_active' => 1,
'created_at' => (new DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new DateTime())->format('Y-m-d H:i:s')
]);
foreach ($languages as $language) {
$localeTo = $rootLocale;
if (!empty($supplierType['names'][$language['locale']])) {
$localeTo = $language['locale'];
} elseif (!empty($supplierType['names'][$defaultLocale])) {
$localeTo = $defaultLocale;
}
$this->connection->insert('suppliers_bundle__supplier_type_translations', [
'object_id' => $supplierTypeId,
'locale' => $language['locale'],
'field' => 'name',
'content' => $supplierType['names'][$localeTo]
]);
}
}
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier DROP FOREIGN KEY FK_FCE3DD2F4584665A');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier DROP FOREIGN KEY FK_FCE3DD2F9941A932');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier DROP FOREIGN KEY FK_FCE3DD2F2ADD6D8C');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier DROP FOREIGN KEY FK_FCE3DD2FB03A8386');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier DROP FOREIGN KEY FK_FCE3DD2F896DBBDE');
$this->addSql('ALTER TABLE suppliers_bundle__product_supplier DROP FOREIGN KEY FK_FCE3DD2FC76F1F52');
$this->addSql('ALTER TABLE suppliers_bundle__supplier DROP FOREIGN KEY FK_DC54A5DAF92F3E70');
$this->addSql('ALTER TABLE suppliers_bundle__supplier DROP FOREIGN KEY FK_DC54A5DA36126D7C');
$this->addSql('ALTER TABLE suppliers_bundle__supplier DROP FOREIGN KEY FK_DC54A5DA4429F88C');
$this->addSql('ALTER TABLE suppliers_bundle__supplier DROP FOREIGN KEY FK_DC54A5DAB03A8386');
$this->addSql('ALTER TABLE suppliers_bundle__supplier DROP FOREIGN KEY FK_DC54A5DA896DBBDE');
$this->addSql('ALTER TABLE suppliers_bundle__supplier DROP FOREIGN KEY FK_DC54A5DAC76F1F52');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address DROP FOREIGN KEY FK_2052C0582ADD6D8C');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address DROP FOREIGN KEY FK_2052C058F92F3E70');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address DROP FOREIGN KEY FK_2052C05836126D7C');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address DROP FOREIGN KEY FK_2052C058B03A8386');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address DROP FOREIGN KEY FK_2052C058896DBBDE');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_address DROP FOREIGN KEY FK_2052C058C76F1F52');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact DROP FOREIGN KEY FK_617E49E12ADD6D8C');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact DROP FOREIGN KEY FK_617E49E1B03A8386');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact DROP FOREIGN KEY FK_617E49E1896DBBDE');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_contact DROP FOREIGN KEY FK_617E49E1C76F1F52');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_context DROP FOREIGN KEY FK_CF412AA72ADD6D8C');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_context DROP FOREIGN KEY FK_CF412AA76B00C1CF');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type DROP FOREIGN KEY FK_2E33A582B03A8386');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type DROP FOREIGN KEY FK_2E33A582896DBBDE');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type DROP FOREIGN KEY FK_2E33A582C76F1F52');
$this->addSql('ALTER TABLE suppliers_bundle__supplier_type_translations DROP FOREIGN KEY FK_5C93F504232D562B');
$this->addSql('DROP TABLE suppliers_bundle__product_supplier');
$this->addSql('DROP TABLE suppliers_bundle__supplier');
$this->addSql('DROP TABLE suppliers_bundle__supplier_address');
$this->addSql('DROP TABLE suppliers_bundle__supplier_contact');
$this->addSql('DROP TABLE suppliers_bundle__supplier_context');
$this->addSql('DROP TABLE suppliers_bundle__supplier_type');
$this->addSql('DROP TABLE suppliers_bundle__supplier_type_translations');
}
}