Commit 7a18e347 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Correction de bug : DDL anciennes et nouvelles inversées!!!

Utilisation de la BDD du Schéma plutôt que de OseAdmin
parent ebb636d8
Loading
Loading
Loading
Loading
+4 −34
Original line number Diff line number Diff line
<?php

if (!$oa->bddIsOk($msg)) {
    $c->printDie("Impossible d'accéder à la base de données : $msg!"
        . "\nVeuillez contrôler vos paramètres de configuration s'il vous plaît, avant de refaire une tentative de MAJ de la base de données (./bin/ose update-bdd).");
}
$bdd = new \BddAdmin\Bdd(Config::get('bdds', 'deploy-local'));
$oa->setBdd($bdd);

$bdd    = $oa->getBdd();
$schema = new \BddAdmin\Schema($bdd);

$c->println("\nMise à jour de la base de données", $c::COLOR_LIGHT_CYAN);

$c->println("\n" . 'Mise à jour des définitions de la base de données', $c::COLOR_LIGHT_PURPLE);

/* Récupération du schéma de référence */
$ref = $schema->loadFromFile($oa->getOseDir() . 'data/ddl.php');

@@ -25,29 +18,6 @@ foreach ($ref as $ddlClass => $objects) {

$mm = new MigrationManager($oa, $schema);
$mm->initTablesDef($ref, $ddlConfig);
$mm->migration('pre');

/* Mise en place du logging en mode console */
$scl          = new \BddAdmin\SchemaConsoleLogger();
$scl->console = $c;
$schema->setLogger($scl);

/* Mise à jour de la BDD */
//$schema->alter($ref, $ddlConfig, true);

/* Mise à jour des séquences */
$c->println("\n" . 'Mise à jour des séquences', $c::COLOR_LIGHT_PURPLE);
//$schema->majSequences($ref);

$c->println("\n" . 'Contrôle et mise à jour des données', $c::COLOR_LIGHT_PURPLE);
$dataGen = new DataGen($oa);
//$dataGen->update();

$c->println('');
$mm->migration('post');

$c->println("\n" . 'Mise à jour du point d\'indice pour les HETD', $c::COLOR_LIGHT_PURPLE);
//$bdd->exec('BEGIN OSE_FORMULE.UPDATE_ANNEE_TAUX_HETD; END;');

// Néttoyage des caches
//$oa->run('clear-cache', false);
 No newline at end of file
$r = $mm->testUtile('FormuleMigrationVolumeHoraireStructuresTestVersCode');
var_dump($r);
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ class DepartementsInitCodes extends AbstractMigration
    {
        $oa = $this->manager->getOseAdmin();

        $bdd = $oa->getBdd();
        $bdd = $this->manager->getSchema()->getBdd();

        $sql     = "
        SELECT 
@@ -44,7 +44,7 @@ class DepartementsInitCodes extends AbstractMigration
        $oa = $this->manager->getOseAdmin();

        $sql = "UPDATE DEPARTEMENT SET CODE = SOURCE_CODE WHERE CODE IS NULL AND SOURCE_ID= :source";
        $oa->getBdd()->exec($sql, ['source' => $oa->getSourceOseId()]);
        $this->manager->getSchema()->getBdd()->exec($sql, ['source' => $oa->getSourceOseId()]);
    }

}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class FormuleMigrationIntervenantStructuresTestVersCode extends AbstractMigratio

    public function apres()
    {
        $bdd = $this->manager->getOseAdmin()->getBdd();
        $bdd = $this->manager->getSchema()->getBdd();

        $sql  = "
        SELECT 
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class FormuleMigrationVolumeHoraireStructuresTestVersCode extends AbstractMigrat

    public function apres()
    {
        $bdd = $this->manager->getOseAdmin()->getBdd();
        $bdd = $this->manager->getSchema()->getBdd();

        $sql  = "
        SELECT 
+17 −8
Original line number Diff line number Diff line
@@ -64,15 +64,15 @@ class MigrationManager
        $ddlConfig                        = [$tablesKey => $ddlConfig[$tablesKey]];
        $ddlConfig['explicit']            = true;
        $ddlConfig['include-tables-deps'] = false;
        $newRef                           = $this->schema->getDdl($ddlConfig);
        $oldRef                           = $this->schema->getDdl($ddlConfig);
        $this->tablesDiff                 = [];
        if (isset($ref[$tablesKey]) && is_array($ref[$tablesKey])) {
            foreach ($ref[$tablesKey] as $table => $ddl) {
        if (isset($oldRef[$tablesKey]) && is_array($oldRef[$tablesKey])) {
            foreach ($oldRef[$tablesKey] as $table => $ddl) {
                $this->tablesDiff[$table]['old'] = $ddl;
            }
        }
        if (isset($newRef[$tablesKey]) && is_array($newRef[$tablesKey])) {
            foreach ($newRef[$tablesKey] as $table => $ddl) {
        if (isset($ref[$tablesKey]) && is_array($ref[$tablesKey])) {
            foreach ($ref[$tablesKey] as $table => $ddl) {
                $this->tablesDiff[$table]['new'] = $ddl;
            }
        }
@@ -196,7 +196,7 @@ class MigrationManager
    protected function tableRealExists($tableName): bool
    {
        $sql = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = :tableName";
        $tn  = $this->oseAdmin->getBdd()->select($sql, compact('tableName'), \BddAdmin\Bdd::FETCH_ONE);
        $tn  = $this->getSchema()->getBdd()->select($sql, compact('tableName'), \BddAdmin\Bdd::FETCH_ONE);

        return isset($tn['TABLE_NAME']) && $tn['TABLE_NAME'] == $tableName;
    }
@@ -206,7 +206,7 @@ class MigrationManager
    public function sauvegarderTable(string $tableName, string $name)
    {
        if ($this->tableRealExists($tableName) && !$this->tableRealExists($name)) {
            $this->oseAdmin->getBdd()->exec("CREATE TABLE $name AS SELECT * FROM $tableName");
            $this->getSchema()->getBdd()->exec("CREATE TABLE $name AS SELECT * FROM $tableName");
        }
    }

@@ -215,7 +215,7 @@ class MigrationManager
    public function supprimerSauvegarde(string $name)
    {
        if ($this->tableRealExists($name)) {
            $this->oseAdmin->getBdd()->exec("DROP TABLE $name");
            $this->getSchema()->getBdd()->exec("DROP TABLE $name");
        }
    }

@@ -272,6 +272,15 @@ class MigrationManager



    public function testUtile($action): bool
    {
        $migration = $this->getMigrationObject($action);

        return $migration instanceof AbstractMigration;
    }



    public function migration(string $context = 'pre', string $action = null)
    {
        if (!is_dir($this->getMigrationDir())) return;