<?php
declare(strict_types=1);
namespace RecurringInvoicesBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
final class Version20221207104305 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE recurring_invoices_bundle__recurring_invoice (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', customer_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', invoice_address_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', delivery_address_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', currency_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', payment_term_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', canceled_by_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)\', currency_change_rate NUMERIC(20, 12) NOT NULL, reference VARCHAR(255) DEFAULT NULL, internal_name VARCHAR(255) DEFAULT NULL, external_name VARCHAR(255) DEFAULT NULL, reduced_vat TINYINT(1) NOT NULL, total_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_no_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_tax_amount NUMERIC(20, 6) DEFAULT NULL, total_amount NUMERIC(20, 6) DEFAULT NULL, last_invoice_generation DATE DEFAULT NULL, next_invoice_generation DATE DEFAULT NULL, daily_recurrence INT DEFAULT NULL, monthly_recurrence INT DEFAULT NULL, annual_recurrence INT DEFAULT NULL, max_invoices INT DEFAULT NULL, auto_validation TINYINT(1) NOT NULL, finished TINYINT(1) NOT NULL, options JSON NOT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, canceled_at DATETIME DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_6B9712E6B00C1CF (context_id), INDEX IDX_6B9712E9395C3F3 (customer_id), INDEX IDX_6B9712EC6BDFEB (invoice_address_id), INDEX IDX_6B9712EEBF23851 (delivery_address_id), INDEX IDX_6B9712E38248176 (currency_id), INDEX IDX_6B9712E17653B16 (payment_term_id), INDEX IDX_6B9712E1418957 (canceled_by_id), INDEX IDX_6B9712EB03A8386 (created_by_id), INDEX IDX_6B9712E896DBBDE (updated_by_id), INDEX IDX_6B9712EC76F1F52 (deleted_by_id), INDEX internal_name (internal_name), INDEX total_amount_untaxed (total_amount_untaxed), INDEX total_amount (total_amount), INDEX is_active (is_active), INDEX canceled_at (canceled_at), 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 recurring_invoices_bundle__recurring_invoice_line (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', recurring_invoice_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', line_type_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', tax_rule_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', parent_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)\', is_group TINYINT(1) NOT NULL, reference VARCHAR(128) DEFAULT NULL, reference_brand VARCHAR(128) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, unit_price NUMERIC(20, 6) DEFAULT NULL, quantity NUMERIC(20, 6) DEFAULT NULL, wholesale_price NUMERIC(20, 6) DEFAULT NULL, margin_ratio NUMERIC(20, 6) DEFAULT NULL, percentage_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_no_discount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_amount_untaxed NUMERIC(20, 6) DEFAULT NULL, total_tax_amount NUMERIC(20, 6) DEFAULT NULL, total_amount NUMERIC(20, 6) DEFAULT NULL, position INT NOT NULL, options JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_BD96F0689F85F85C (recurring_invoice_id), INDEX IDX_BD96F06870E80DF4 (line_type_id), INDEX IDX_BD96F0683506A35B (tax_rule_id), INDEX IDX_BD96F068727ACA70 (parent_id), INDEX IDX_BD96F068B03A8386 (created_by_id), INDEX IDX_BD96F068896DBBDE (updated_by_id), INDEX IDX_BD96F068C76F1F52 (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('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E6B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E9395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EC6BDFEB FOREIGN KEY (invoice_address_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EEBF23851 FOREIGN KEY (delivery_address_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E38248176 FOREIGN KEY (currency_id) REFERENCES currency (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E17653B16 FOREIGN KEY (payment_term_id) REFERENCES sales_bundle__payment_term (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E1418957 FOREIGN KEY (canceled_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712E896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice ADD CONSTRAINT FK_6B9712EC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F0689F85F85C FOREIGN KEY (recurring_invoice_id) REFERENCES recurring_invoices_bundle__recurring_invoice (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F06870E80DF4 FOREIGN KEY (line_type_id) REFERENCES sales_bundle__line_type (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F0683506A35B FOREIGN KEY (tax_rule_id) REFERENCES tax_rule (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068727ACA70 FOREIGN KEY (parent_id) REFERENCES recurring_invoices_bundle__recurring_invoice_line (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line ADD CONSTRAINT FK_BD96F068C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE sales_bundle__invoice ADD recurring_invoice_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE sales_bundle__invoice ADD CONSTRAINT FK_BB8C2B4C9F85F85C FOREIGN KEY (recurring_invoice_id) REFERENCES recurring_invoices_bundle__recurring_invoice (id)');
$this->addSql('CREATE INDEX IDX_BB8C2B4C9F85F85C ON sales_bundle__invoice (recurring_invoice_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE sales_bundle__invoice DROP FOREIGN KEY FK_BB8C2B4C9F85F85C');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E6B00C1CF');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E9395C3F3');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EC6BDFEB');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EEBF23851');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E38248176');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E17653B16');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E1418957');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EB03A8386');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712E896DBBDE');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice DROP FOREIGN KEY FK_6B9712EC76F1F52');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F0689F85F85C');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F06870E80DF4');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F0683506A35B');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068727ACA70');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068B03A8386');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068896DBBDE');
$this->addSql('ALTER TABLE recurring_invoices_bundle__recurring_invoice_line DROP FOREIGN KEY FK_BD96F068C76F1F52');
$this->addSql('DROP TABLE recurring_invoices_bundle__recurring_invoice');
$this->addSql('DROP TABLE recurring_invoices_bundle__recurring_invoice_line');
$this->addSql('DROP INDEX IDX_BB8C2B4C9F85F85C ON sales_bundle__invoice');
$this->addSql('ALTER TABLE sales_bundle__invoice DROP recurring_invoice_id');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$configurations = [
'recurring_invoices_bundle__reference_format' => 'FA-REC/[[number]]',
'recurring_invoices_bundle__automatic_invoice_validation_default' => true
];
foreach ($configurations as $configuration => $value) {
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => $configuration,
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => $value]),
'created_at' => $now,
'updated_at' => $now
]);
}
$this->connection->insert('cron_job', [
'name' => 'recurring-invoices-check-generation',
'command' => 'bluue-bundle:recurring-invoices:check-generation',
'schedule' => '0 6 * * *',
'description' => '',
'enabled' => 1
]);
}
}