Skip to content

Commit

Permalink
avoid use of sql to migrate table
Browse files Browse the repository at this point in the history
  • Loading branch information
sualko committed Jan 31, 2022
1 parent e3e55dc commit 158fc1f
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions lib/Migration/Version7Date20220125174818.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,32 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$schema = $schemaClosure();
$tableprefix = "gestion_";

/** @var \Doctrine\DBAL\Schema\Table $table */
/**Client**/
if (!$schema->hasTable($tableprefix.'client')) {
$table = $schema->createTable($tableprefix.'client');
} else {
$table = $schema->getTable($tableprefix.'client');
}
$table = $schema->getTable($tableprefix.'client');

if (!$table->hasColumn('id')) {
$table->addColumn('id', 'integer', ['autoincrement' => true,'notnull' => true,]);
$table->setPrimaryKey(['id']);
}
if (!$table->hasColumn('nom')) {
$table->addColumn('nom', 'text', []);
$table->addColumn('nom', 'text', []);
}
if (!$table->hasColumn('prenom')) {
$table->addColumn('prenom', 'text', []);
}
if (!$table->hasColumn('siret')) {
}else{
$stmt = $this->db->prepare("ALTER TABLE `".'*PREFIX*'."gestion_client` CHANGE `siret` `legal_one` LONGTEXT");
$stmt->execute();
if ($table->hasColumn('siret')) {
$table->changeColumn('siret', [
'type' => 'longtext',
]);

$table->changeColumn('legal_one', [
'type' => 'longtext',
]);
}

if (!$table->hasColumn('legal_one')) {
Expand All @@ -83,8 +90,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
/**Configuration**/
if (!$schema->hasTable($tableprefix.'configuration')) {
$table = $schema->createTable($tableprefix.'configuration');
} else {
$table = $schema->getTable($tableprefix.'configuration');
}
$table = $schema->getTable($tableprefix.'configuration');

if (!$table->hasColumn('id')) {
$table->addColumn('id', 'integer', ['autoincrement' => true,'notnull' => true,]);
$table->setPrimaryKey(['id']);
Expand All @@ -102,16 +111,24 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addColumn('prenom', 'text', []);
}

if (!$table->hasColumn('siret')) {
}else{
$stmt = $this->db->prepare("ALTER TABLE `".'*PREFIX*'."gestion_configuration` CHANGE `siret` `legal_one` LONGTEXT");
$stmt->execute();
if ($table->hasColumn('siret')) {
$table->changeColumn('siret', [
'type' => 'longtext',
]);

$table->changeColumn('legal_one', [
'type' => 'longtext',
]);
}

if (!$table->hasColumn('siren')) {
}else{
$stmt = $this->db->prepare("ALTER TABLE `".'*PREFIX*'."gestion_configuration` CHANGE `siren` `legal_two` LONGTEXT");
$stmt->execute();
if ($table->hasColumn('siren')) {
$table->changeColumn('siret', [
'type' => 'longtext',
]);

$table->changeColumn('legal_one', [
'type' => 'longtext',
]);
}

if (!$table->hasColumn('legal_one')) {
Expand Down Expand Up @@ -173,18 +190,19 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
if (!$table->hasColumn('id_nextcloud')) {
$table->addColumn('id_nextcloud', 'string', ['length' => 64]);
}

/**DEVIS**/
if (!$schema->hasTable($tableprefix.'devis')) {
$table = $schema->createTable($tableprefix.'devis');
} else {
$table = $schema->getTable($tableprefix.'devis');
}

$table = $schema->getTable($tableprefix.'devis');
if (!$table->hasColumn('id')) {
$table->addColumn('id', 'integer', ['autoincrement' => true,'notnull' => true]);
$table->setPrimaryKey(['id']);
}

if (!$table->hasColumn('date')) {
$table->addColumn('date', 'date', []);
}
Expand Down Expand Up @@ -224,7 +242,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

/**FACTURE**/
if (!$schema->hasTable($tableprefix.'facture')) {
$table = $schema->createTable($tableprefix.'facture');
$table = $schema->createTable($tableprefix.'facture');
}

$table = $schema->getTable($tableprefix.'facture');
Expand All @@ -249,14 +267,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
if (!$table->hasColumn('type_paiement')) {
$table->addColumn('type_paiement', 'string', ['length' => 64]);
}

if (!$table->hasColumn('status_paiement')) {
$table->addColumn('status_paiement', 'string', ['length' => 64, 'default' => 'NC']);
}else{
$column = $table->getColumn('status_paiement');
$column->setOptions(['default' => 'NC']);
}

if (!$table->hasColumn('version')) {
$table->addColumn('version', 'string', ['length' => 64, 'default' => '1.0']);
}else{
Expand Down

0 comments on commit 158fc1f

Please sign in to comment.