From ba346708c321eee779f01a0e748a81e91eab73f1 Mon Sep 17 00:00:00 2001 From: jmontoya Date: Wed, 24 Feb 2016 17:27:13 +0100 Subject: [PATCH] Fix session_rel_user table if session does not exists. --- app/Migrations/Schema/V110/Version110.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Migrations/Schema/V110/Version110.php b/app/Migrations/Schema/V110/Version110.php index 5f14f72f42..cef10faee8 100644 --- a/app/Migrations/Schema/V110/Version110.php +++ b/app/Migrations/Schema/V110/Version110.php @@ -49,12 +49,13 @@ class Version110 extends AbstractMigrationChamilo $this->addSql("ALTER TABLE skill_rel_user MODIFY COLUMN acquired_skill_at datetime default NULL"); $this->addSql("ALTER TABLE track_e_access MODIFY COLUMN access_date datetime DEFAULT NULL"); $this->addSql("ALTER TABLE track_e_lastaccess MODIFY COLUMN access_date datetime DEFAULT NULL"); - - $this->addSql("ALTER TABLE skill_rel_user ADD COLUMN course_id INT NOT NULL DEFAULT 0 AFTER id"); $this->addSql("ALTER TABLE skill_rel_user ADD COLUMN session_id INT NOT NULL DEFAULT 0 AFTER course_id"); $this->addSql("ALTER TABLE skill_rel_user ADD INDEX idx_select_cs (course_id, session_id)"); + // Delete info of session_rel_user if session does not exists; + $this->addSql("DELETE FROM session_rel_user WHERE id_session NOT IN (SELECT id FROM session)"); + $session = $schema->getTable('session'); $session->getColumn('id')->setType(Type::getType(Type::INTEGER))->setUnsigned(false); if (!$session->hasColumn('description')) {