| Total Complexity | 63 |
| Total Lines | 365 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Version20181025064351 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Version20181025064351, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Version20181025064351 extends AbstractMigrationChamilo |
||
| 13 | { |
||
| 14 | public function getDescription(): string |
||
| 17 | } |
||
| 18 | |||
| 19 | public function up(Schema $schema): void |
||
| 20 | { |
||
| 21 | $table = $schema->getTable('gradebook_result_log'); |
||
| 22 | if ($table->hasColumn('id_result')) { |
||
| 23 | $this->addSql('DELETE FROM gradebook_result_log WHERE id_result IS NULL'); |
||
| 24 | $this->addSql('ALTER TABLE gradebook_result_log CHANGE id_result result_id INT DEFAULT NULL'); |
||
| 25 | } |
||
| 26 | |||
| 27 | $this->addSql('UPDATE gradebook_result_log SET evaluation_id = NULL WHERE evaluation_id = 0'); |
||
| 28 | $this->addSql('ALTER TABLE gradebook_result_log CHANGE evaluation_id evaluation_id INT DEFAULT NULL'); |
||
| 29 | |||
| 30 | $this->addSql('UPDATE gradebook_result_log SET user_id = NULL WHERE user_id = 0'); |
||
| 31 | $this->addSql('ALTER TABLE gradebook_result_log CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 32 | |||
| 33 | if (false === $table->hasForeignKey('FK_C5C4CABB7A7B643')) { |
||
| 34 | $this->addSql( |
||
| 35 | 'ALTER TABLE gradebook_result_log ADD CONSTRAINT FK_C5C4CABB7A7B643 FOREIGN KEY (result_id) REFERENCES gradebook_result (id) ON DELETE CASCADE;' |
||
| 36 | ); |
||
| 37 | $this->addSql('CREATE INDEX IDX_C5C4CABB7A7B643 ON gradebook_result_log (result_id)'); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (false === $table->hasForeignKey('FK_C5C4CABB456C5646')) { |
||
| 41 | $this->addSql( |
||
| 42 | 'ALTER TABLE gradebook_result_log ADD CONSTRAINT FK_C5C4CABB456C5646 FOREIGN KEY (evaluation_id) REFERENCES gradebook_evaluation (id) ON DELETE CASCADE;' |
||
| 43 | ); |
||
| 44 | $this->addSql('CREATE INDEX IDX_C5C4CABB456C5646 ON gradebook_result_log (evaluation_id);'); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (false === $table->hasForeignKey('FK_C5C4CABBA76ED395')) { |
||
| 48 | $this->addSql( |
||
| 49 | 'ALTER TABLE gradebook_result_log ADD CONSTRAINT FK_C5C4CABBA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE' |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | if (false === $table->hasIndex('IDX_C5C4CABBA76ED395')) { |
||
| 54 | $this->addSql('CREATE INDEX IDX_C5C4CABBA76ED395 ON gradebook_result_log (user_id)'); |
||
| 55 | } |
||
| 56 | |||
| 57 | $table = $schema->getTable('gradebook_category'); |
||
| 58 | |||
| 59 | $this->addSql('ALTER TABLE gradebook_category CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 60 | $this->addSql( |
||
| 61 | 'DELETE FROM gradebook_category WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM user)' |
||
| 62 | ); |
||
| 63 | |||
| 64 | if ($table->hasIndex('idx_gb_cat_parent')) { |
||
| 65 | $this->addSql(' DROP INDEX idx_gb_cat_parent ON gradebook_category;'); |
||
| 66 | } |
||
| 67 | |||
| 68 | $this->addSql('UPDATE gradebook_category SET session_id = NULL WHERE session_id = 0'); |
||
| 69 | $this->addSql('UPDATE gradebook_category SET parent_id = NULL WHERE parent_id = 0'); |
||
| 70 | |||
| 71 | if (false === $table->hasForeignKey('FK_96A4C705727ACA70')) { |
||
| 72 | $this->addSql('ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705727ACA70 FOREIGN KEY (parent_id) REFERENCES gradebook_category (id);'); |
||
| 73 | } |
||
| 74 | |||
| 75 | if (false === $table->hasForeignKey('FK_96A4C705613FECDF')) { |
||
| 76 | $this->addSql('ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE;'); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (false === $table->hasIndex('IDX_96A4C705613FECDF')) { |
||
| 80 | $this->addSql('CREATE INDEX IDX_96A4C705613FECDF ON gradebook_category (session_id)'); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (false === $table->hasIndex('IDX_96A4C705727ACA70')) { |
||
| 84 | $this->addSql('CREATE INDEX IDX_96A4C705727ACA70 ON gradebook_category (parent_id);'); |
||
| 85 | } |
||
| 86 | |||
| 87 | if (false === $table->hasColumn('c_id')) { |
||
| 88 | $this->addSql('ALTER TABLE gradebook_category ADD c_id INT DEFAULT NULL'); |
||
| 89 | $this->addSql('UPDATE gradebook_category SET c_id = (SELECT id FROM course WHERE code = course_code)'); |
||
| 90 | $this->addSql('ALTER TABLE gradebook_category DROP course_code'); |
||
| 91 | $this->addSql( |
||
| 92 | 'ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C70591D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE' |
||
| 93 | ); |
||
| 94 | $this->addSql('CREATE INDEX IDX_96A4C70591D79BD3 ON gradebook_category (c_id);'); |
||
| 95 | } |
||
| 96 | if (false === $table->hasColumn('depends')) { |
||
| 97 | $this->addSql('ALTER TABLE gradebook_category ADD depends LONGTEXT DEFAULT NULL'); |
||
| 98 | } |
||
| 99 | if (false === $table->hasColumn('minimum_to_validate')) { |
||
| 100 | $this->addSql('ALTER TABLE gradebook_category ADD minimum_to_validate INT DEFAULT NULL'); |
||
| 101 | } |
||
| 102 | if (false === $table->hasColumn('gradebooks_to_validate_in_dependence')) { |
||
| 103 | $this->addSql('ALTER TABLE gradebook_category ADD gradebooks_to_validate_in_dependence INT DEFAULT NULL'); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (false === $table->hasForeignKey('FK_96A4C705A76ED395')) { |
||
| 107 | $this->addSql( |
||
| 108 | 'ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)' |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | if (false === $table->hasIndex('IDX_96A4C705A76ED395')) { |
||
| 112 | $this->addSql('CREATE INDEX IDX_96A4C705A76ED395 ON gradebook_category (user_id)'); |
||
| 113 | } |
||
| 114 | |||
| 115 | if (!$table->hasForeignKey('FK_96A4C705378B7921')) { |
||
| 116 | $this->addSql('ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705378B7921 FOREIGN KEY (grade_model_id) REFERENCES grade_model (id) ON DELETE CASCADE;'); |
||
| 117 | } |
||
| 118 | if (!$table->hasIndex('IDX_96A4C705378B7921')) { |
||
| 119 | $this->addSql('CREATE INDEX IDX_96A4C705378B7921 ON gradebook_category (grade_model_id);'); |
||
| 120 | } |
||
| 121 | |||
| 122 | // grade_components. |
||
| 123 | $table = $schema->getTable('grade_components'); |
||
| 124 | |||
| 125 | $this->addSql('ALTER TABLE grade_components CHANGE grade_model_id grade_model_id INT DEFAULT NULL'); |
||
| 126 | if (!$table->hasForeignKey('FK_F34247C378B7921')) { |
||
| 127 | $this->addSql('ALTER TABLE grade_components ADD CONSTRAINT FK_F34247C378B7921 FOREIGN KEY (grade_model_id) REFERENCES grade_model (id) ON DELETE CASCADE;'); |
||
| 128 | } |
||
| 129 | if (!$table->hasIndex('IDX_F34247C378B7921')) { |
||
| 130 | $this->addSql('CREATE INDEX IDX_F34247C378B7921 ON grade_components (grade_model_id);'); |
||
| 131 | } |
||
| 132 | |||
| 133 | // Evaluation. |
||
| 134 | $table = $schema->getTable('gradebook_evaluation'); |
||
| 135 | if (false === $table->hasColumn('c_id')) { |
||
| 136 | $this->addSql('ALTER TABLE gradebook_evaluation ADD c_id INT DEFAULT NULL'); |
||
| 137 | $this->addSql('UPDATE gradebook_evaluation SET c_id = (SELECT id FROM course WHERE code = course_code)'); |
||
| 138 | $this->addSql('ALTER TABLE gradebook_evaluation DROP course_code'); |
||
| 139 | $this->addSql( |
||
| 140 | 'ALTER TABLE gradebook_evaluation ADD CONSTRAINT FK_DDDED80491D79BD3 FOREIGN KEY (c_id) REFERENCES course (id);' |
||
| 141 | ); |
||
| 142 | $this->addSql('CREATE INDEX IDX_DDDED80491D79BD3 ON gradebook_evaluation (c_id)'); |
||
| 143 | //$this->addSql('ALTER TABLE gradebook_evaluation RENAME INDEX fk_ddded80491d79bd3 TO IDX_DDDED80491D79BD3;'); |
||
| 144 | } |
||
| 145 | if (false === $table->hasIndex('idx_ge_cat')) { |
||
| 146 | $this->addSql('CREATE INDEX idx_ge_cat ON gradebook_evaluation (category_id)'); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (false === $table->hasForeignKey('FK_DDDED80412469DE2')) { |
||
| 150 | $this->addSql('ALTER TABLE gradebook_evaluation ADD CONSTRAINT FK_DDDED80412469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id) ON DELETE CASCADE'); |
||
| 151 | } |
||
| 152 | |||
| 153 | if (false === $table->hasColumn('best_score')) { |
||
| 154 | $this->addSql('ALTER TABLE gradebook_evaluation ADD best_score DOUBLE PRECISION DEFAULT NULL'); |
||
| 155 | } |
||
| 156 | if (false === $table->hasColumn('average_score')) { |
||
| 157 | $this->addSql('ALTER TABLE gradebook_evaluation ADD average_score DOUBLE PRECISION DEFAULT NULL'); |
||
| 158 | } |
||
| 159 | if (false === $table->hasColumn('score_weight')) { |
||
| 160 | $this->addSql('ALTER TABLE gradebook_evaluation ADD score_weight DOUBLE PRECISION DEFAULT NULL'); |
||
| 161 | } |
||
| 162 | if (false === $table->hasColumn('user_score_list')) { |
||
| 163 | $this->addSql( |
||
| 164 | 'ALTER TABLE gradebook_evaluation ADD user_score_list LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\'' |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | $this->addSql('ALTER TABLE gradebook_evaluation CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 168 | |||
| 169 | if (false === $table->hasForeignKey('FK_DDDED804A76ED395')) { |
||
| 170 | $this->addSql( |
||
| 171 | 'ALTER TABLE gradebook_evaluation ADD CONSTRAINT FK_DDDED804A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE' |
||
| 172 | ); |
||
| 173 | } |
||
| 174 | |||
| 175 | if (false === $table->hasIndex('IDX_DDDED804A76ED395')) { |
||
| 176 | $this->addSql('CREATE INDEX IDX_DDDED804A76ED395 ON gradebook_evaluation (user_id)'); |
||
| 177 | } |
||
| 178 | |||
| 179 | $table = $schema->getTable('gradebook_link'); |
||
| 180 | if (false === $table->hasColumn('c_id')) { |
||
| 181 | $this->addSql('ALTER TABLE gradebook_link ADD c_id INT DEFAULT NULL'); |
||
| 182 | $this->addSql('UPDATE gradebook_link SET c_id = (SELECT id FROM course WHERE code = course_code)'); |
||
| 183 | $this->addSql('ALTER TABLE gradebook_link DROP course_code'); |
||
| 184 | $this->addSql( |
||
| 185 | 'ALTER TABLE gradebook_link ADD CONSTRAINT FK_4F0F595F91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id);' |
||
| 186 | ); |
||
| 187 | $this->addSql('CREATE INDEX IDX_4F0F595F91D79BD3 ON gradebook_link (c_id);'); |
||
| 188 | } |
||
| 189 | |||
| 190 | if (false === $table->hasColumn('best_score')) { |
||
| 191 | $this->addSql('ALTER TABLE gradebook_link ADD best_score DOUBLE PRECISION DEFAULT NULL'); |
||
| 192 | } |
||
| 193 | if (false === $table->hasColumn('average_score')) { |
||
| 194 | $this->addSql( |
||
| 195 | 'ALTER TABLE gradebook_link ADD average_score DOUBLE PRECISION DEFAULT NULL' |
||
| 196 | ); |
||
| 197 | } |
||
| 198 | |||
| 199 | if (false === $table->hasColumn('score_weight')) { |
||
| 200 | $this->addSql('ALTER TABLE gradebook_link ADD score_weight DOUBLE PRECISION DEFAULT NULL'); |
||
| 201 | } |
||
| 202 | |||
| 203 | if (false === $table->hasColumn('user_score_list')) { |
||
| 204 | $this->addSql( |
||
| 205 | 'ALTER TABLE gradebook_link ADD user_score_list LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\'' |
||
| 206 | ); |
||
| 207 | } |
||
| 208 | |||
| 209 | if (false === $table->hasIndex('idx_gl_cat')) { |
||
| 210 | $this->addSql('CREATE INDEX idx_gl_cat ON gradebook_link (category_id)'); |
||
| 211 | } |
||
| 212 | |||
| 213 | $this->addSql('ALTER TABLE gradebook_link CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 214 | |||
| 215 | if (false === $table->hasForeignKey('FK_4F0F595FA76ED395')) { |
||
| 216 | $this->addSql( |
||
| 217 | 'ALTER TABLE gradebook_link ADD CONSTRAINT FK_4F0F595FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE' |
||
| 218 | ); |
||
| 219 | } |
||
| 220 | |||
| 221 | if (false === $table->hasIndex('IDX_4F0F595FA76ED395')) { |
||
| 222 | $this->addSql('CREATE INDEX IDX_4F0F595FA76ED395 ON gradebook_link (user_id)'); |
||
| 223 | } |
||
| 224 | |||
| 225 | $this->addSql('ALTER TABLE gradebook_link CHANGE category_id category_id INT DEFAULT NULL;'); |
||
| 226 | $this->addSql('UPDATE gradebook_link SET category_id = NULL WHERE category_id = 0'); |
||
| 227 | |||
| 228 | if (false === $table->hasForeignKey('FK_4F0F595F12469DE2')) { |
||
| 229 | $this->addSql('ALTER TABLE gradebook_link ADD CONSTRAINT FK_4F0F595F12469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id) ON DELETE CASCADE'); |
||
| 230 | } |
||
| 231 | |||
| 232 | $table = $schema->getTable('gradebook_result'); |
||
| 233 | |||
| 234 | if (false === $table->hasIndex('idx_gb_uid_eid')) { |
||
| 235 | $this->addSql('CREATE INDEX idx_gb_uid_eid ON gradebook_result (user_id, evaluation_id);'); |
||
| 236 | } |
||
| 237 | |||
| 238 | if (false === $table->hasIndex('IDX_B88AEB67456C5646')) { |
||
| 239 | $this->addSql('CREATE INDEX IDX_B88AEB67456C5646 ON gradebook_result (evaluation_id);'); |
||
| 240 | } |
||
| 241 | |||
| 242 | $this->addSql('ALTER TABLE gradebook_result CHANGE evaluation_id evaluation_id INT DEFAULT NULL;'); |
||
| 243 | $this->addSql('UPDATE gradebook_result SET evaluation_id = NULL WHERE evaluation_id = 0'); |
||
| 244 | |||
| 245 | if (false === $table->hasForeignKey('FK_B88AEB67456C5646')) { |
||
| 246 | $this->addSql('ALTER TABLE gradebook_result ADD CONSTRAINT FK_B88AEB67456C5646 FOREIGN KEY (evaluation_id) REFERENCES gradebook_evaluation (id) ON DELETE CASCADE'); |
||
| 247 | } |
||
| 248 | |||
| 249 | $this->addSql('ALTER TABLE gradebook_result CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 250 | $this->addSql('UPDATE gradebook_result SET user_id = NULL WHERE user_id = 0'); |
||
| 251 | |||
| 252 | if (false === $table->hasForeignKey('FK_B88AEB67A76ED395')) { |
||
| 253 | $this->addSql( |
||
| 254 | 'ALTER TABLE gradebook_result ADD CONSTRAINT FK_B88AEB67A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE' |
||
| 255 | ); |
||
| 256 | } |
||
| 257 | |||
| 258 | if (false === $table->hasIndex('IDX_B88AEB67A76ED395')) { |
||
| 259 | $this->addSql('CREATE INDEX IDX_B88AEB67A76ED395 ON gradebook_result (user_id)'); |
||
| 260 | } |
||
| 261 | |||
| 262 | $table = $schema->getTable('gradebook_certificate'); |
||
| 263 | $this->addSql('ALTER TABLE gradebook_certificate CHANGE cat_id cat_id INT DEFAULT NULL;'); |
||
| 264 | $this->addSql('UPDATE gradebook_certificate SET cat_id = NULL WHERE cat_id = 0'); |
||
| 265 | |||
| 266 | if (false === $table->hasForeignKey('FK_650669DE6ADA943')) { |
||
| 267 | if ($table->hasIndex('idx_gradebook_certificate_category_id')) { |
||
| 268 | $this->addSql('DROP INDEX idx_gradebook_certificate_category_id ON gradebook_certificate;'); |
||
| 269 | } |
||
| 270 | |||
| 271 | if ($table->hasIndex('idx_gradebook_certificate_category_id_user_id')) { |
||
| 272 | $this->addSql('DROP INDEX idx_gradebook_certificate_category_id_user_id ON gradebook_certificate;'); |
||
| 273 | } |
||
| 274 | $this->addSql('ALTER TABLE gradebook_certificate ADD CONSTRAINT FK_650669DE6ADA943 FOREIGN KEY (cat_id) REFERENCES gradebook_category (id) ON DELETE CASCADE;'); |
||
| 275 | } |
||
| 276 | |||
| 277 | if (false === $table->hasColumn('downloaded_at')) { |
||
| 278 | $this->addSql('ALTER TABLE gradebook_certificate ADD downloaded_at DATETIME DEFAULT NULL;'); |
||
| 279 | $this->addSql( |
||
| 280 | 'UPDATE gradebook_certificate gc SET downloaded_at = ( |
||
| 281 | SELECT value from extra_field e |
||
| 282 | INNER JOIN extra_field_values v on v.field_id = e.id |
||
| 283 | WHERE variable = "downloaded_at" and extra_field_type = 11 and item_id = gc.id |
||
| 284 | )' |
||
| 285 | ); |
||
| 286 | } |
||
| 287 | |||
| 288 | $this->addSql('ALTER TABLE gradebook_certificate CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 289 | |||
| 290 | if (false === $table->hasForeignKey('FK_650669DA76ED395')) { |
||
| 291 | $this->addSql( |
||
| 292 | 'ALTER TABLE gradebook_certificate ADD CONSTRAINT FK_650669DA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE' |
||
| 293 | ); |
||
| 294 | } |
||
| 295 | |||
| 296 | if (false === $table->hasIndex('IDX_650669DE6ADA943')) { |
||
| 297 | $this->addSql('CREATE INDEX IDX_650669DE6ADA943 ON gradebook_certificate (cat_id);'); |
||
| 298 | } |
||
| 299 | |||
| 300 | if (false === $schema->hasTable('gradebook_result_attempt')) { |
||
| 301 | $this->addSql( |
||
| 302 | 'CREATE TABLE gradebook_result_attempt (id INT AUTO_INCREMENT NOT NULL, comment LONGTEXT DEFAULT NULL, score DOUBLE PRECISION DEFAULT NULL, result_id INT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB ROW_FORMAT = DYNAMIC;' |
||
| 303 | ); |
||
| 304 | |||
| 305 | $this->addSql('ALTER TABLE gradebook_result_attempt ADD CONSTRAINT FK_28B1CC3F7A7B643 FOREIGN KEY (result_id) REFERENCES gradebook_result (id) ON DELETE CASCADE;'); |
||
| 306 | $this->addSql('CREATE INDEX IDX_28B1CC3F7A7B643 ON gradebook_result_attempt (result_id);'); |
||
| 307 | } else { |
||
| 308 | $table = $schema->getTable('gradebook_result_attempt'); |
||
| 309 | $this->addSql('UPDATE gradebook_result_attempt SET result_id = NULL WHERE result_id = 0'); |
||
| 310 | $this->addSql('ALTER TABLE gradebook_result_attempt CHANGE result_id result_id INT DEFAULT NULL'); |
||
| 311 | if (!$table->hasForeignKey('FK_28B1CC3F7A7B643')) { |
||
| 312 | $this->addSql('ALTER TABLE gradebook_result_attempt ADD CONSTRAINT FK_28B1CC3F7A7B643 FOREIGN KEY (result_id) REFERENCES gradebook_result (id) ON DELETE CASCADE;'); |
||
| 313 | } |
||
| 314 | |||
| 315 | if (!$table->hasIndex('IDX_28B1CC3F7A7B643')) { |
||
| 316 | $this->addSql('CREATE INDEX IDX_28B1CC3F7A7B643 ON gradebook_result_attempt (result_id);'); |
||
| 317 | } |
||
| 318 | } |
||
| 319 | |||
| 320 | if (false === $table->hasForeignKey('FK_1F554C7474C99BA2')) { |
||
| 321 | } |
||
| 322 | |||
| 323 | $table = $schema->getTable('gradebook_linkeval_log'); |
||
| 324 | |||
| 325 | $this->addSql('UPDATE gradebook_linkeval_log SET user_id_log = NULL WHERE user_id_log = 0'); |
||
| 326 | $this->addSql('ALTER TABLE gradebook_linkeval_log CHANGE user_id_log user_id_log INT DEFAULT NULL'); |
||
| 327 | |||
| 328 | if (false === $table->hasForeignKey('FK_1F554C7474C99BA2')) { |
||
| 329 | $this->addSql( |
||
| 330 | 'ALTER TABLE gradebook_linkeval_log ADD CONSTRAINT FK_1F554C7474C99BA2 FOREIGN KEY (user_id_log) REFERENCES user (id) ON DELETE CASCADE' |
||
| 331 | ); |
||
| 332 | } |
||
| 333 | |||
| 334 | if (false === $table->hasIndex('IDX_1F554C7474C99BA2')) { |
||
| 335 | $this->addSql('CREATE INDEX IDX_1F554C7474C99BA2 ON gradebook_linkeval_log (user_id_log)'); |
||
| 336 | } |
||
| 337 | |||
| 338 | $table = $schema->getTable('gradebook_score_log'); |
||
| 339 | |||
| 340 | $this->addSql('ALTER TABLE gradebook_score_log CHANGE user_id user_id INT DEFAULT NULL'); |
||
| 341 | $this->addSql('ALTER TABLE gradebook_score_log CHANGE category_id category_id INT DEFAULT NULL;'); |
||
| 342 | |||
| 343 | if (false === $table->hasForeignKey('FK_640C6449A76ED395')) { |
||
| 344 | $this->addSql( |
||
| 345 | 'ALTER TABLE gradebook_score_log ADD CONSTRAINT FK_640C6449A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE' |
||
| 346 | ); |
||
| 347 | } |
||
| 348 | |||
| 349 | if (false === $table->hasForeignKey('FK_640C644912469DE2')) { |
||
| 350 | $this->addSql( |
||
| 351 | 'ALTER TABLE gradebook_score_log ADD CONSTRAINT FK_640C644912469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id) ON DELETE CASCADE;' |
||
| 352 | ); |
||
| 353 | } |
||
| 354 | |||
| 355 | if (false === $table->hasIndex('IDX_640C644912469DE2')) { |
||
| 356 | $this->addSql('CREATE INDEX IDX_640C644912469DE2 ON gradebook_score_log (category_id);'); |
||
| 357 | } |
||
| 358 | |||
| 359 | $table = $schema->hasTable('gradebook_comment'); |
||
| 360 | if (false === $table) { |
||
| 361 | $this->addSql('CREATE TABLE gradebook_comment (id BIGINT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, gradebook_id INT DEFAULT NULL, comment LONGTEXT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_C3B70763A76ED395 (user_id), INDEX IDX_C3B70763AD3ED51C (gradebook_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;'); |
||
| 362 | $this->addSql('ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;'); |
||
| 363 | $this->addSql('ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763AD3ED51C FOREIGN KEY (gradebook_id) REFERENCES gradebook_category (id) ON DELETE CASCADE;'); |
||
| 364 | } |
||
| 365 | |||
| 366 | $table = $schema->getTable('gradebook_score_display'); |
||
| 367 | $this->addSql('ALTER TABLE gradebook_score_display CHANGE category_id category_id INT DEFAULT NULL;'); |
||
| 368 | $this->addSql('UPDATE gradebook_score_display SET category_id = NULL WHERE category_id = 0'); |
||
| 369 | |||
| 370 | if (false === $table->hasForeignKey('FK_61F7DC8412469DE2')) { |
||
| 371 | $this->addSql('ALTER TABLE gradebook_score_display ADD CONSTRAINT FK_61F7DC8412469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id) ON DELETE CASCADE;'); |
||
| 372 | } |
||
| 373 | } |
||
| 374 | |||
| 375 | public function down(Schema $schema): void |
||
| 377 | } |
||
| 378 | } |
||
| 379 |