fix: fiabiliser les portées et médias publics

This commit is contained in:
Alexandre NOEL 2026-09-15 18:39:00 +02:00
commit 4493357590
11 changed files with 121 additions and 6 deletions

View file

@ -65,6 +65,32 @@ final class Migrations
}
}
// Deux anciens schémas de l’historique ont circulé : l’un avec
// action/field/values, l’autre avec type/label/details. Le code
// courant accepte les données des deux et a besoin de leur union.
if ($name === '096_animal_history_compatibility.sql') {
$columns = array_column(
$db->query('PRAGMA table_info(animal_history)')->fetchAll(PDO::FETCH_ASSOC),
'name',
);
$definitions = [
'action' => "TEXT NOT NULL DEFAULT 'history'",
'field' => 'TEXT',
'old_value' => 'TEXT',
'new_value' => 'TEXT',
'meta' => 'TEXT',
'type' => "TEXT NOT NULL DEFAULT 'history'",
'label' => "TEXT NOT NULL DEFAULT ''",
'details' => 'TEXT',
'user_id' => 'INTEGER',
];
foreach ($definitions as $column => $definition) {
if (!in_array($column, $columns, true)) {
$db->exec("ALTER TABLE animal_history ADD COLUMN $column $definition");
}
}
}
$relaxesForeignKeys = $name === '093_room_rules_and_care_periods.sql';
if ($relaxesForeignKeys) {
$db->exec('PRAGMA foreign_keys = OFF');