<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20230426152301 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function preUp(Schema $schema): void
{
$this->connection->executeQuery('DELETE FROM member_application WHERE original_data_id IS NOT NULL');
}
public function up(Schema $schema): void
{
$this->skipIf(
true === $schema->getTable('member_application')->hasColumn('member_application_original_data_id'),
'The member_application_original_data_id field was already added in the member_application table!'
);
$memberApplicationTable = $schema->getTable('member_application');
if ($memberApplicationTable->hasIndex('uniq_member_application_original_data_id')) {
$memberApplicationTable->dropIndex('uniq_member_application_original_data_id');
}
$memberApplicationTable->dropColumn('original_data_id');
$originalDataTable = $schema->createTable('member_application_original_data');
$originalDataTable->addColumn('id', Types::INTEGER, ['notnull' => true]);
$originalDataTable->addColumn('member_application_id', Types::INTEGER, ['notnull' => true]);
$originalDataTable->addColumn('health_insurance_id', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('health_mutual_id', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('subscription_plan_id', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('company_id', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('resource_id', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('type', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('last_name', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('first_name', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('sex', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('birth_date', Types::DATETIME_IMMUTABLE, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('civil_status', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('civil_status_certificate', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('social_security_number', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('is_previously_cmcm_member', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('affiliate_number', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('phone_number', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('mobile_number', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('fax_number', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('email', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('iban', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('financial_institution', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('has_health_mutual', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('creditor_identification', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('mandate_reference', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('contract_number', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('comment', Types::TEXT, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('is_all_data_accepted', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('payment_frequency', Types::STRING, ['length' => 30, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('language', Types::STRING, ['length' => 10, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('address_certificate', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('has_complementary_health_insurance', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('complementary_health_insurance_name', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('complementary_health_insurance_certificate', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('health_insurance_certificate', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('bank_certificate', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('bic', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('member_ship_start_at', Types::DATETIME_IMMUTABLE, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('insured_care_start_at', Types::DATETIME_IMMUTABLE, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('is_general_condition_accepted', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('is_gdpr_accepted', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('has_signed_with_company', Types::BOOLEAN, ['notnull' => true, 'default' => false]);
$originalDataTable->addColumn('created_at', Types::DATETIME_IMMUTABLE, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('deleted_at', Types::DATETIME_IMMUTABLE, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('company_employee_identifier', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('email_confirmed_at', Types::DATETIME_IMMUTABLE, ['notnull' => false, 'default' => null]);
$originalDataTable->addColumn('house_number', Types::STRING, ['length' => 10, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('street_line', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('street_line2', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('postal_code', Types::STRING, ['length' => 10, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('city', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('country', Types::STRING, ['length' => 255, 'notnull' => false, 'default' => null]);
$originalDataTable->addColumn('member_application_co_members', Types::JSON, ['notnull' => false, 'default' => null]);
$originalDataTable->addForeignKeyConstraint('member_application', ['member_application_id'], ['id'], [], 'fk_member_application_id');
$originalDataTable->addForeignKeyConstraint('health_insurance', ['health_insurance_id'], ['id'], [], 'fk_health_insurance_id');
$originalDataTable->addForeignKeyConstraint('health_mutual', ['health_mutual_id'], ['id'], [], 'fk_health_mutual_id');
$originalDataTable->addForeignKeyConstraint('subscription_plan', ['subscription_plan_id'], ['id'], [], 'fk_subscription_plan_id');
$originalDataTable->addForeignKeyConstraint('company', ['company_id'], ['id'], [], 'fk_company_id');
$originalDataTable->setPrimaryKey(['id'], 'uniq_member_application_original_data_id');
$originalDataTable->addUniqueIndex(['resource_id'], 'uniq_member_application_original_data_resource_id');
$originalDataTable->addUniqueIndex(['member_application_id'], 'uniq_member_application_original_data_member_application_id');
$memberApplicationTable->addUniqueIndex(['resource_id'], 'uniq_member_application_resource_id');
$memberApplicationTable->addIndex(['health_insurance_id'], 'uniq_member_application_original_data_health_insurance_id');
$memberApplicationTable->addIndex(['health_mutual_id'], 'uniq_member_application_original_data_health_mutual_id');
$memberApplicationTable->addIndex(['subscription_plan_id'], 'uniq_member_application_original_data_subscription_plan_id');
$memberApplicationTable->addIndex(['company_id'], 'uniq_member_application_original_data_company_id');
}
public function down(Schema $schema): void
{
// Not handled as update won't be downgraded.
// $this->skipIf(
// false === $schema->getTable('member_application')->hasColumn('original_data_id'),
// 'The original_data_id field was already removed from the member_application table!'
// );
//
// $schema->getTable('member_application')->dropColumn('original_data_id');
//
// $schema->getTable('member_application')->dropIndex(
// 'uniq_member_application_original_data_id'
// );
}
}