Version20160405112100.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Application\Migrations\Schema\V111;
  3. use Application\Migrations\AbstractMigrationChamilo;
  4. use Doctrine\DBAL\Schema\Schema;
  5. class Version20160405112100 extends AbstractMigrationChamilo
  6. {
  7. /**
  8. * @param Schema $schema
  9. */
  10. public function up(Schema $schema)
  11. {
  12. $this->addSql(
  13. 'CREATE TABLE skill_level_profile (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  14. );
  15. $this->addSql(
  16. 'CREATE TABLE skill_level (id INT AUTO_INCREMENT NOT NULL, profile_id INT NOT NULL, name VARCHAR(255) NOT NULL, position INT, short_name VARCHAR(255), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  17. );
  18. $this->addSql(
  19. 'ALTER TABLE skill_rel_user ADD acquired_level INT, ADD argumentation TEXT, ADD argumentation_author_id INT, MODIFY course_id INT, MODIFY session_id INT'
  20. );
  21. $this->addSql(
  22. 'CREATE TABLE skill_rel_user_comment (id INT AUTO_INCREMENT NOT NULL, skill_rel_user_id INT NOT NULL, feedback_giver_id INT NOT NULL, feedback_text TEXT, feedback_value INT, feedback_datetime DATETIME, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  23. );
  24. $this->addSql('ALTER TABLE skill ADD profile_id INT');
  25. if ($schema->hasTable('skill')) {
  26. $table = $schema->getTable('skill');
  27. if ($table->hasForeignKey('FK_5E3DE477CCFA12B8') == false) {
  28. $this->addSql('ALTER TABLE skill ADD CONSTRAINT FK_5E3DE477CCFA12B8 FOREIGN KEY (profile_id) REFERENCES skill_level_profile (id);');
  29. }
  30. if ($table->hasIndex('IDX_5E3DE477CCFA12B8') == false) {
  31. $this->addSql('CREATE INDEX IDX_5E3DE477CCFA12B8 ON skill (profile_id);');
  32. }
  33. }
  34. // Skill
  35. if ($schema->hasTable('skill')) {
  36. $this->addSql('ALTER TABLE skill CHANGE name name VARCHAR(255) NOT NULL, CHANGE short_code short_code VARCHAR(100) NOT NULL, CHANGE description description LONGTEXT NOT NULL, CHANGE icon icon VARCHAR(255) NOT NULL, CHANGE updated_at updated_at DATETIME NOT NULL;');
  37. }
  38. // skill_rel_user
  39. if ($schema->hasTable('skill_rel_user')) {
  40. $table = $schema->getTable('skill_rel_user');
  41. $this->addSql('ALTER TABLE skill_rel_user CHANGE acquired_skill_at acquired_skill_at DATETIME NOT NULL, CHANGE argumentation argumentation LONGTEXT NOT NULL, CHANGE argumentation_author_id argumentation_author_id INT NOT NULL;');
  42. $this->addSql('UPDATE skill_rel_user SET course_id = NULL WHERE course_id = 0');
  43. $this->addSql('UPDATE skill_rel_user SET skill_id = NULL WHERE skill_id = 0');
  44. $this->addSql('UPDATE skill_rel_user SET user_id = NULL WHERE user_id = 0');
  45. $this->addSql('UPDATE skill_rel_user SET session_id = NULL WHERE session_id = 0');
  46. $this->addSql('UPDATE skill_rel_user SET acquired_level = NULL WHERE acquired_level = 0');
  47. if ($table->hasForeignKey('FK_79D3D95AA76ED395') == false) {
  48. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95AA76ED395 FOREIGN KEY (user_id) REFERENCES user (id);');
  49. }
  50. if ($table->hasForeignKey('FK_79D3D95A5585C142') == false) {
  51. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95A5585C142 FOREIGN KEY (skill_id) REFERENCES skill (id);');
  52. }
  53. if ($table->hasForeignKey('FK_79D3D95A591CC992') == false) {
  54. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95A591CC992 FOREIGN KEY (course_id) REFERENCES course (id);');
  55. }
  56. if ($table->hasForeignKey('FK_79D3D95A613FECDF') == false) {
  57. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95A613FECDF FOREIGN KEY (session_id) REFERENCES session (id);');
  58. }
  59. if ($table->hasForeignKey('FK_79D3D95AF68F11CE') == false) {
  60. $this->addSql('ALTER TABLE skill_rel_user ADD CONSTRAINT FK_79D3D95AF68F11CE FOREIGN KEY (acquired_level) REFERENCES skill_level (id);');
  61. }
  62. if ($table->hasIndex('IDX_79D3D95AA76ED395') == false) {
  63. $this->addSql('CREATE INDEX IDX_79D3D95AA76ED395 ON skill_rel_user(user_id);');
  64. }
  65. if ($table->hasIndex('IDX_79D3D95A5585C142') == false) {
  66. $this->addSql('CREATE INDEX IDX_79D3D95A5585C142 ON skill_rel_user(skill_id);');
  67. }
  68. if ($table->hasIndex('IDX_79D3D95A591CC992') == false) {
  69. $this->addSql('CREATE INDEX IDX_79D3D95A591CC992 ON skill_rel_user(course_id);');
  70. }
  71. if ($table->hasIndex('IDX_79D3D95A613FECDF') == false) {
  72. $this->addSql('CREATE INDEX IDX_79D3D95A613FECDF ON skill_rel_user(session_id);');
  73. }
  74. if ($table->hasIndex('IDX_79D3D95AF68F11CE') == false) {
  75. $this->addSql('CREATE INDEX IDX_79D3D95AF68F11CE ON skill_rel_user (acquired_level);');
  76. }
  77. if ($table->hasIndex('IDX_79D3D95AF68F11CE') == false) {
  78. $this->addSql('CREATE INDEX idx_select_s_c_u ON skill_rel_user (session_id, course_id, user_id);');
  79. }
  80. if ($table->hasIndex('IDX_79D3D95AF68F11CE') == false) {
  81. $this->addSql('CREATE INDEX idx_select_sk_u ON skill_rel_user(skill_id, user_id);');
  82. }
  83. }
  84. // skill_level
  85. if ($schema->hasTable('skill_level')) {
  86. $table = $schema->getTable('skill_level');
  87. $this->addSql('ALTER TABLE skill_level CHANGE profile_id profile_id INT DEFAULT NULL, CHANGE position position INT NOT NULL, CHANGE short_name short_name VARCHAR(255) NOT NULL;');
  88. if ($table->hasForeignKey('FK_BFC25F2FCCFA12B8') == false) {
  89. $this->addSql('ALTER TABLE skill_level ADD CONSTRAINT FK_BFC25F2FCCFA12B8 FOREIGN KEY (profile_id) REFERENCES skill_level_profile (id);');
  90. }
  91. if ($table->hasIndex('IDX_BFC25F2FCCFA12B8') == false) {
  92. $this->addSql('CREATE INDEX IDX_BFC25F2FCCFA12B8 ON skill_level (profile_id);');
  93. }
  94. }
  95. }
  96. /**
  97. * @param Schema $schema
  98. */
  99. public function down(Schema $schema)
  100. {
  101. $this->addSql(
  102. 'ALTER TABLE skill_rel_user DROP COLUMN acquired_level, DROP COLUMN argumentation, DROP COLUMN argumentation_author_id, MODIFY course_id INT NOT NULL, MODIFY session_id INT NOT NULL'
  103. );
  104. $this->addSql(
  105. 'ALTER TABLE skill DROP COLUMN profile_id'
  106. );
  107. $this->addSql('DROP TABLE skill_level');
  108. $this->addSql('DROP TABLE skill_level_profile');
  109. }
  110. }