Commit 17ff14b8 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Ajout d'exists sur les managers d'objets

Renforcement des contrôles de scripts de migration v20
parent b48cc502
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -28,7 +28,12 @@ class v20Contrats extends AbstractMigration

        $c->begin("Convertion des contrats de travail en états de sortie");

        $modeles = $bdd->select("SELECT * FROM modele_contrat");
        $this->manager->sauvegarderTable('MODELE_CONTRAT', 'SAVE_MODELE_CONTRAT');
        // On supprime l'ancienne table afin de ne jamais recommencer la migration, puis on travaille sur la sauvegarde

        $bdd->table()->drop('MODELE_CONTRAT');

        $modeles = $bdd->select("SELECT * FROM SAVE_MODELE_CONTRAT");

        $etatsSortie = [];
        $statuts     = [];
+13 −2
Original line number Diff line number Diff line
@@ -28,8 +28,19 @@ class v20Divers extends AbstractMigration

        $c->begin("Préparation de la migration vers la version 20");

        $bdd->exec("ALTER TABLE TYPE_INTERVENTION DROP CONSTRAINT TYPE_INTERVENTION_CODE_UN");
        $bdd->exec("DROP INDEX TYPE_INTERVENTION_CODE_UN");
        if ($bdd->uniqueConstraint()->exists('TYPE_INTERVENTION_CODE_UN')) {
            $bdd->uniqueConstraint()->drop('TYPE_INTERVENTION_CODE_UN');
        }
        if ($bdd->index()->exists('TYPE_INTERVENTION_CODE_UN')){
            $bdd->index()->drop('TYPE_INTERVENTION_CODE_UN');
        }

        if ($bdd->uniqueConstraint()->exists('TI_STATUT_STATUT_UN')) {
            $bdd->uniqueConstraint()->drop('TI_STATUT_STATUT_UN');
        }
        if ($bdd->index()->exists('TI_STATUT_STATUT_UN')){
            $bdd->index()->drop('TI_STATUT_STATUT_UN');
        }

        $oseAppliId = $this->manager->getOseAdmin()->getOseAppliId();
        $bdd->exec("UPDATE TYPE_INTERVENTION_STATUT SET HISTO_CREATEUR_ID = $oseAppliId WHERE HISTO_CREATEUR_ID IS NULL");
+1 −4
Original line number Diff line number Diff line
@@ -13,10 +13,7 @@ abstract class AbstractManagerDdlConstraint extends AbstractManager

    protected function indexExists($indexName)
    {
        $sql = "SELECT count(*) RES FROM ALL_INDEXES WHERE INDEX_NAME = :indexName AND ROWNUM = 1";
        $res = $this->bdd->select($sql, compact('indexName'), ['fetch' => Bdd::FETCH_ONE]);

        return $res['RES'] == '1';
        return $this->bdd->index()->exists($indexName);
    }


+13 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace BddAdmin\Driver\Oracle;

use BddAdmin\Bdd;
use BddAdmin\Manager\AbstractManager;
use BddAdmin\Manager\IndexManagerInterface;
use BddAdmin\Ddl\DdlFilter;
@@ -75,6 +76,18 @@ class IndexManager extends AbstractManager implements IndexManagerInterface



    public function exists(string $name): bool
    {
        $sql = "SELECT count(*) NBR FROM all_indexes WHERE index_name = :name";
        $params = ['name' => $name];

        $nbr = (int)$this->bdd->select($sql, $params, ['fetch' => Bdd::FETCH_ONE])['NBR'];

        return $nbr > 0;
    }



    protected function makeCreate(array $data)
    {
        $sql = "CREATE ";
+13 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace BddAdmin\Driver\Oracle;

use BddAdmin\Bdd;
use BddAdmin\Manager\AbstractManager;
use BddAdmin\Manager\MaterializedViewManagerInteface;
use BddAdmin\Ddl\DdlFilter;
@@ -59,6 +60,18 @@ class MaterializedViewManager extends AbstractManager implements MaterializedVie



    public function exists(string $name): bool
    {
        $sql = "SELECT count(*) NBR FROM ALL_MVIEWS WHERE OWNER = sys_context( 'userenv', 'current_schema' ) AND mview_name = :name";
        $params = ['name' => $name];

        $nbr = (int)$this->bdd->select($sql, $params, ['fetch' => Bdd::FETCH_ONE])['NBR'];

        return $nbr > 0;
    }



    public function create(array $data)
    {
        if ($this->sendEvent()->getReturn('no-exec')) return;
Loading