Commit 96cbba44 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Mise à jour automatique des séquences, pour éviter tout problème de chevauchement d'ID

parent 49b83229
......@@ -3,6 +3,10 @@
$bdd = new \BddAdmin\Bdd(Config::get()['bdds']['dev-local']);
//$bdd->debug = true;
$schema = new \BddAdmin\Schema($bdd);
$schema->majSequences();
$oa = new OseAdmin();
$oa->setBdd($bdd);
......
......@@ -40,9 +40,12 @@ $schema->setLogger($scl);
/* Mise à jour de la BDD */
$schema->alter($ref, $ddlConfig, true);
$c->println('');
$c->println('Mise à jour des données', $c::COLOR_LIGHT_PURPLE);
/* Mise à jour des séquences */
$c->println("\n".'Mise à jour des séquences', $c::COLOR_LIGHT_PURPLE);
$schema->majSequences($ref);
$c->println("\n".'Mise à jour des données', $c::COLOR_LIGHT_PURPLE);
$dataGen = new DataGen($oa);
$dataGen->update();
......
......@@ -254,12 +254,15 @@ class DdlTable extends DdlAbstract
public function majSequence(array $data)
{
if (!isset($data['sequence'])) return;
if (!isset($data['columns']['ID'])) return;
$sql = 'DECLARE seqId NUMERIC;
BEGIN
SELECT COALESCE(MAX(id+1),1) INTO seqId FROM ' . $data['name'] . ';
EXECUTE IMMEDIATE \'DROP SEQUENCE ' . $data['sequence'] . '\';
EXECUTE IMMEDIATE \'CREATE SEQUENCE ' . $data['sequence'] . ' INCREMENT BY 1 MINVALUE \' || seqId || \' NOCACHE\';
END';
END;';
$this->addQuery($sql, 'Mise à jour de la séquence '.$data['sequence']);
}
......
......@@ -497,9 +497,9 @@ class Schema
if ($ddlObject->getQueries()) {
if ($autoExecute) {
return [DdlTable::class . '.majSequences' => $ddlObject->execQueries()];
return [DdlTable::class . '.majSequences' => $ddlObject->execQueries($this->logger)];
} else {
return [DdlTable::class . '.majSequences' => $ddlObject->getQueries()];
return [DdlTable::class . '.majSequences' => $ddlObject->getQueries($this->logger)];
}
}
}
......
......@@ -122,8 +122,8 @@ class DataGen
{
foreach ($this->config as $table => $params) {
if (isset($params['title'])) {
echo ' * ' . $params['title'] . ' ...' . "\n"; // provisoire
//$this->oseAdmin->getConsole()->println(' * ' . $params['title'] . ' ...');
echo $params['title'] . "\n"; // provisoire
//$this->oseAdmin->getConsole()->println($params['title']);
}
$data = $this->$table();
$this->oseAdmin->getBdd()->getTable($table)->merge(
......
......@@ -303,9 +303,11 @@ class OseAdmin
*/
public function migration(string $prePost = 'pre'): bool
{
$this->console->println('Exécution des scripts de ' . $prePost . '-migration', $this->console::COLOR_LIGHT_PURPLE);
$scripts = $this->getMigrationFilesToExecute($this->oldVersion, $this->version, $prePost);
if (count($scripts) > 0) {
$this->console->println('Exécution des scripts de ' . $prePost . '-migration', $this->console::COLOR_LIGHT_PURPLE);
}
foreach ($scripts as $script) {
$ext = substr($script, -3);
switch ($ext) {
......@@ -320,8 +322,6 @@ class OseAdmin
if (count($scripts) > 0) {
$this->console->println("Scripts de $prePost-migration exécutés");
} else {
$this->console->println("Aucun script de $prePost-migration à exécuter");
}
return true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment