Closed vignemail1 closed 3 years ago
La conversion du dump SQL initial en une migration (structure de tables uniquement) peut être réalisée avec la commande suivante dans un projet ayant toutes les tables et champs chargées en base de données.
root@gramc:/var/www/gramc3# ./bin/console doctrine:migrations:dump-schema
Dumped your schema to a new migration class at "/var/www/gramc3/migrations/Version20210610164732.php"
To run just this migration for testing purposes, you can use migrations:execute --up 'DoctrineMigrations\\Version20210610164732'
To revert the migration you can use migrations:execute --down 'DoctrineMigrations\\Version20210610164732'
To use this as a rollup migration you can use the migrations:rollup command.
En utilisant ./bin/console doctrine:migrations:diff
et les entities existantes, cela génère une migration qui contient les instructions nécessaires pour rajouter les champs manquants ainsi que la table formation elle aussi manquante.
root@gramc:/var/www/gramc3# ./bin/console doctrine:migrations:diff
Generated new migration class to "/var/www/gramc3/migrations/Version20210610193644.php"
To run just this migration for testing purposes, you can use migrations:execute --up 'DoctrineMigrations\\Version20210610193644'
To revert the migration you can use migrations:execute --down 'DoctrineMigrations\\Version20210610193644'
root@gramc:/var/www/gramc3# ./bin/console doctrine:migrations:execute --up 'DoctrineMigrations\Version20210610193644'
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
> yes
[notice] Executing DoctrineMigrations\Version20210610193644 up
[notice] finished in 972.4ms, used 18M memory, 1 migrations executed, 4 sql queries
migration générée :
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210610193644 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE formation (id INT AUTO_INCREMENT NOT NULL, numero_form INT DEFAULT NULL, acro_form VARCHAR(15) DEFAULT NULL, nom_form VARCHAR(100) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('DROP TABLE consommation');
$this->addSql('ALTER TABLE user ADD cpassword VARCHAR(200) DEFAULT NULL');
$this->addSql('ALTER TABLE version ADD dem_form_0 INT DEFAULT NULL, ADD dem_form_1 INT DEFAULT NULL, ADD dem_form_2 INT DEFAULT NULL, ADD dem_form_3 INT DEFAULT NULL, ADD dem_form_4 INT DEFAULT NULL, ADD dem_form_5 INT DEFAULT NULL, ADD dem_form_6 INT DEFAULT NULL, ADD dem_form_7 INT DEFAULT NULL, ADD dem_form_8 INT DEFAULT NULL, ADD dem_form_9 INT DEFAULT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE consommation (id INT AUTO_INCREMENT NOT NULL, id_projet VARCHAR(6) CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`, annee INT NOT NULL, limite INT NOT NULL, m01 INT NOT NULL, m02 INT NOT NULL, m03 INT NOT NULL, m04 INT NOT NULL, m05 INT NOT NULL, m06 INT NOT NULL, m07 INT NOT NULL, m08 INT NOT NULL, m09 INT NOT NULL, m10 INT NOT NULL, m11 INT NOT NULL, m12 INT NOT NULL, INDEX annee_2 (annee), INDEX id_projet_2 (id_projet), INDEX id_projet (id_projet), INDEX annee (annee), UNIQUE INDEX id_projet_3 (id_projet, annee), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('DROP TABLE formation');
$this->addSql('ALTER TABLE user DROP cpassword');
$this->addSql('ALTER TABLE version DROP dem_form_0, DROP dem_form_1, DROP dem_form_2, DROP dem_form_3, DROP dem_form_4, DROP dem_form_5, DROP dem_form_6, DROP dem_form_7, DROP dem_form_8, DROP dem_form_9');
}
}
Nous utilisons les doctrine/data-fixtures pour faire évoluer la base de données. Pour installer une base de données, que ce soit une base exportée depuis la prod ou une base, on doit exécuter le script reload-db dans le répertoire reprise
Description du problème
Contexte: version de la branche feature/criann, commit
Différentes pages de la section Administrateur sont indisponibles (remontent des Exceptions) dû à des champs de la DB qui sont manquants voire même de table(s) manquante(s).
Par exemple, la page
/gramc3/projet/donnees
retourne :Proposition de solutions
Il pourrait également être intéressant d'étudier le cas d'un champ de type JSON pour stocker les données de formulaire dont la structure peut évoluer au gré des besoins (https://mariadb.com/kb/en/json_search/ , https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#json).