Thanasoft-Hytha/gestion/lib/Migration/Version20001Date20250812120000.php
2025-08-18 14:49:35 +03:00

53 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\Gestion\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use OCP\IDBConnection;
/**
* Migration pour ajouter le champ is_tva à la table oc_gestion_client
*/
class Version20001Date20250812120000 extends SimpleMigrationStep
{
private IDbConnection $db;
public function __construct(IDbConnection $db)
{
$this->db = $db;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper
{
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$tableprefix = "gestion_";
// Vérifier si la table existe
if ($schema->hasTable($tableprefix.'client')) {
$table = $schema->getTable($tableprefix.'client');
// Ajouter le champ is_tva s'il n'existe pas déjà
if (!$table->hasColumn('is_tva')) {
$table->addColumn('is_tva', 'smallint', [
'notnull' => true,
'default' => 1,
'comment' => 'Indique si le client est assujetti à la TVA (1=oui, 0=non)',
'unsigned' => true,
'length' => 1
]);
$output->info('Champ is_tva ajouté à la table gestion_client');
return $schema;
}
}
return null;
}
}